Ejemplo n.º 1
0
        public void Awake()
        {
            m_tank = this.GetParent <Tank>();
            wheels = m_tank.GameObject.FindComponentInChildren <Transform>("wheels");

            tracks = m_tank.GameObject.FindComponentInChildren <Transform>("tracks");

            motorAudioSource = m_tank.GameObject.GetComponent <AudioSource>();

            if (this.motorAudioSource == null)
            {
                motorAudioSource = m_tank.GameObject.AddComponent <AudioSource>();
            }

            motorAudioSource.playOnAwake = false;

            motorAudioSource.spatialBlend = 1;

            motorAudioSource.volume = GameSettingInfo.AudioVolume();

            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();

            Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"Unit.unity3d");
            GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");

            Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"Unit.unity3d");
            motorClip = bundleGameObject.Get <AudioClip>("motor");

            this.motorAudioSource.loop = true;

            this.motorAudioSource.clip = this.motorClip;

            axleInfos = new List <AxleInfo>(2);

            // 前轮
            AxleInfo axleInfo = new AxleInfo();

            axleInfo.leftWheel  = m_tank.GameObject.FindComponentInChildren <WheelCollider>("PhysicalBody/wheelL1");
            axleInfo.rightWheel = m_tank.GameObject.FindComponentInChildren <WheelCollider>("PhysicalBody/wheelR1");
            axleInfo.montor     = false;
            axleInfo.steering   = true;
            this.axleInfos.Add(axleInfo);
            axleInfo            = new AxleInfo();
            axleInfo.leftWheel  = m_tank.GameObject.FindComponentInChildren <WheelCollider>("PhysicalBody/wheelL2");
            axleInfo.rightWheel = m_tank.GameObject.FindComponentInChildren <WheelCollider>("PhysicalBody/wheelR2");
            axleInfo.montor     = true;
            axleInfo.steering   = false;
            this.axleInfos.Add(axleInfo);
        }
Ejemplo n.º 2
0
        private void InitPhysical()
        {
            wheels = m_tank.FindComponentInChildren <Transform>("wheels");

            tracks = m_tank.FindComponentInChildren <Transform>("tracks");


            motorAudioSource = m_tank.GetComponent <AudioSource>();
            if (motorAudioSource == null)
            {
                motorAudioSource = m_tank.AddComponent <AudioSource>();
            }


            motorAudioSource.spatialBlend = 1;

            motorAudioSource.volume = GameSettingInfo.AudioVolume();

            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();

            //Game.Scene.GetComponent<ResourcesComponent>().LoadBundle($"Unit.unity3d");
            GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset(AssetBundleName.Unit, PrefabName.Unit);

            //Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle($"Unit.unity3d");
            motorClip = bundleGameObject.Get <AudioClip>("motor");

            motorAudioSource.loop = true;

            motorAudioSource.clip = this.motorClip;

            axleInfos = new List <AxleInfo>(2);

            // 前轮 转向轮
            AxleInfo axleInfo = new AxleInfo();

            axleInfo.leftWheel  = m_tank.FindComponentInChildren <WheelCollider>("PhysicalBody/wheelL1");
            axleInfo.rightWheel = m_tank.FindComponentInChildren <WheelCollider>("PhysicalBody/wheelR1");
            axleInfo.montor     = false;
            axleInfo.steering   = true;
            this.axleInfos.Add(axleInfo);
            // 后轮 动力轮
            axleInfo            = new AxleInfo();
            axleInfo.leftWheel  = m_tank.FindComponentInChildren <WheelCollider>("PhysicalBody/wheelL2");
            axleInfo.rightWheel = m_tank.FindComponentInChildren <WheelCollider>("PhysicalBody/wheelR2");
            axleInfo.montor     = true;
            axleInfo.steering   = false;
            this.axleInfos.Add(axleInfo);
        }