unity3d 从其他名称空间导入插件

myss37ts  于 2022-12-13  发布在  其他
关注(0)|答案(1)|浏览(173)

我有这个错误时,导入Pedometer插件。

Assets/gameMaster.cs(7,13): error CS0246: The type or namespace name 'Pedometer' could not be found (are you missing a using directive or an assembly reference?)

在我的gameMaster.cs
我尝试new Pedometer(OnStep);new PedoMeterU.Pedometer(OnStep);
但是,两者都有相同的错误。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class gameMaster : MonoBehaviour
{
    private Pedometer pedometer;
    // Start is called before the first frame update
    void Start()
    {
        pedometer = new Pedometer(OnStep);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    private void OnStep (int steps, double distance) {
        // Display the values // Distance in feet
        stepText.text = steps.ToString();
        //distanceText.text = (distance * 3.28084).ToString("F2") + " ft";
        Debug.Log("steps:" + steps);
    }

    private void OnDisable () {
        // Release the pedometer
        pedometer.Dispose();
        pedometer = null;
    }
}

这是PedometerU插件

namespace PedometerU {

    using UnityEngine;
    using System;
    using Platforms;
    
    public sealed class Pedometer : IDisposable {

        #region --Properties--
        /// <summary>
        /// How many updates has this pedometer received?
        /// Useful for calculating pedometer precision
        /// </summary>
        public int updateCount { get; private set; }
        /// <summary>
        /// The backing implementation Pedometer uses on this platform
        /// </summary>
        public static readonly IPedometer Implementation;
        #endregion

        #region --Op vars--
        private int initialSteps; // Some step counters count from device boot, so subtract the initial count we get
        private double initialDistance;
        private readonly StepCallback callback;
        
        #endregion

        #region --Client API--
        
        /// <summary>
        /// Create a new pedometer and start listening for updates
        /// </summary>
        public Pedometer (StepCallback callback) {
            if (Implementation == null) {
                Debug.LogError("Pedometer Error: Step counting is not supported on this platform");
                return;
            }
            if (callback == null) {
                Debug.LogError("Pedometer Error: Cannot create pedometer instance with null callback");
                return;
            }
            this.callback = callback;
            Implementation.OnStep += OnStep;
        }

        /// <summary>
        /// Stop listening for pedometer updates and dispose the object
        /// </summary>
        public void Dispose () {
            if (Implementation == null) {
                Debug.LogWarning("Pedometer Error: Step counting is not supported on this platform");
                return;
            }
            Implementation.OnStep -= OnStep;
        }
        #endregion

        #region --Operations--

        private void OnStep (int steps, double distance) {
            // Set initials and increment update count
            initialSteps = updateCount++ == 0 ? steps : initialSteps;
            initialDistance = steps == initialSteps ? distance : initialDistance;
            // If this is not the first step, then invoke the callback
            if (steps != initialSteps)
                callback(steps - initialSteps, distance - initialDistance);
        }

        static Pedometer () {
            // Create implementation for this platform
            Implementation =
            #if UNITY_IOS && !UNITY_EDITOR
            new PedometeriOS();
            #elif UNITY_ANDROID && !UNITY_EDITOR
            new PedometerAndroid();
            #else
            null;
            #endif
            PedometerUtility.Initialize();
        }
        #endregion
    }
}
gopyfrb3

gopyfrb31#

您需要在类的顶部添加using PedometerU;,因为Pedometer类是在此命名空间中定义的。

相关问题