33d

using UnityEngine;
using System.Collections;

public class Sun : MonoBehaviour {
  public StateMachine<Sun> m_pStateMachine;
  
  public bool track=true;
  public Texture[] coverSunFrames;
  public Texture[] winFrames;
  public Texture[] trackFrames;
  public Texture[] normalFrames;
  public GameObject childObject;
  
  public bool isRendering=false;
  private float lastTime=0;
  private float curtTime=0;
  
  //private bool lastRendering=false;
  
  //public bool inNothingState=false;
  
  private int index;
  // Use this for initialization
  void Start () {

    tag="Sun";
    
    m_pStateMachine = new StateMachine<Sun>(this);
    m_pStateMachine.SetCurrentState(Sun_NothingState .Instance());
    track=true;
    GameObject theCloud = GameObject.FindWithTag("CoverCloudPS");
    iTween.ScaleTo(theCloud.gameObject,new Vector3(theCloud.gameObject.transform.localScale.x*2.5f,theCloud.gameObject.transform.localScale.y,theCloud.gameObject.transform.localScale.z*4.0f),0.1f);
    theCloud.renderer.enabled = false;
    setTrack(false);

  }
  
  void OnWillRenderObject()
  {
      curtTime=Time.time;
  }
  
  // Update is called once per frame
  void Update () {
    isRendering=curtTime!=lastTime?true:false;
      lastTime=curtTime;
    
    /*
    if(isRendering==true&&lastRendering==false&&TempValue.sunTrackDis>=0){
      //Debug.Log(Time.time+" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~show sun");
      TempValue.sunTrackDis=TempValue.dis;
      lastRendering=true;
    }
    if(isRendering==false&&lastRendering==true&&TempValue.sunTrackDis>=0){
      TempValue.sunTrackDis=TempValue.dis;
      lastRendering=false;
    }
    */
      
    Vector3 tempVec3=transform.position;
    //tempVec3.y=Camera.main.transform.position.y+4.5f;
    //tempVec3.z=Camera.main.transform.position.z;
    tempVec3.y=Camera.main.transform.position.y;
    tempVec3+=new Vector3(0,4.5f,0);
    transform.position=tempVec3;
    
    m_pStateMachine.SMUpdate();
    
    /*
    if(track==false) return;
    
    Vector3 tempVec3=transform.position;
    //tempVec3.y=Camera.main.transform.position.y+4.5f;
    //tempVec3.z=Camera.main.transform.position.z;
    tempVec3.y=Camera.main.transform.position.y;
    tempVec3+=new Vector3(0,4.5f,0);
    transform.position=tempVec3;
    
    GameObject carGameObject= GameObject.FindWithTag("Player");  
    float dis=carGameObject.transform.localPosition.z-transform.position.z;//+originalPosition.localPosition.z;    
    if(dis<32){
      Debug.Log("ok");
      
    }
    else{
      tempVec3=rigidbody.velocity;
      tempVec3.z=MyValues.topSpeedX+6;//carGameObject.rigidbody.velocity.z+0.2f;
      rigidbody.velocity=tempVec3;
    }
    */
  }
  public void setWinState(bool b){
    track=b;
    if(track==true){
      m_pStateMachine.ChangeState(Sun_Win_State.Instance());
    }
    else {
      m_pStateMachine.ChangeState(Sun_Covered_State.Instance());
      //rigidbody.velocity=Vector3.zero;
    }
  }
  public void setTrack(bool b){
    track=b;
    if(track==true){
      TempValue.sunTrackDis=TempValue.dis;
      m_pStateMachine.ChangeState(Sun_TrackState .Instance());
    }
    else{
      m_pStateMachine.ChangeState(Sun_NothingState .Instance());
      //rigidbody.velocity=Vector3.zero;
    }
  }
  public void state_set_CloudCovered(bool isSet){
    if(isSet==true){
      m_pStateMachine.ChangeState(Sun_Covered_State.Instance());
    }
    else{
      //m_pStateMachine.ChangeState(Sun_TrackState.Instance());
      if(track==true){
        m_pStateMachine.ChangeState(Sun_TrackState.Instance());
      }else{
        m_pStateMachine.ChangeState(Sun_NothingState.Instance());
      }

    }
  }
  
  public void loopframe () {
    int nowIndex=(int)(Time.time *6) % coverSunFrames.Length;
    if(index!=nowIndex){
      index  = nowIndex;
      renderer.material.mainTexture = coverSunFrames[index];
    }
  }
  public void loopframe (Texture[] frames) {
    int nowIndex=(int)(Time.time *6) % frames.Length;
    if(index!=nowIndex){
      index  = nowIndex;
      renderer.material.mainTexture = frames[index];
    }
  }
  public StateMachine<Sun> GetFSM ()
  {
    return m_pStateMachine;
  }
}

public class Sun_TrackState :State<Sun>//Track状态
{    

  //private float enterTime;
  
  private static Sun_TrackState instance;
  public static Sun_TrackState Instance ()
  {
    if (instance == null)
      instance = new Sun_TrackState ();
    
    return instance;

  }

  public override void Enter (Sun Entity)
  {
    //base.Enter (Entity);
    //Debug.Log(Time.time+ " enter track");
    
    Vector3 tempVec3=Entity.transform.position;
    //tempVec3.z=Camera.main.transform.position.z-14.0f;
    tempVec3.z=Camera.main.transform.position.z-150.0f;
    Entity.transform.position=tempVec3;
  }

  public override void Execute (Sun Entity)
  {
    //base.Execute (Entity);
    Entity.loopframe(Entity.normalFrames);
    Vector3 tempVec3=Entity.transform.position;
    GameObject carGameObject= GameObject.FindWithTag("Player");  
    float dis=carGameObject.transform.localPosition.z-Entity.transform.position.z;//+originalPosition.localPosition.z;    
    if(dis<32){
      Entity.GetFSM ().ChangeState(Sun_RacingState .Instance());
      return;
    }
    else{
      tempVec3=Entity.rigidbody.velocity;
      tempVec3.z=MyValues.topSpeedX+5+TempValue.dis / MyValues.changeSceneDis;//carGameObject.rigidbody.velocity.z+0.2f;
      tempVec3.z+=MyValues.addSpeedX;
      if (tempVec3.z >= 40)
      {
        // 追击状态下boss最高速度为40m/s
        tempVec3.z = 40;
      }
      Entity.rigidbody.velocity=tempVec3;
    }
  }

  public override void Exit (Sun Entity)
  {
    //base.Exit (Entity);
  }
}

public class Sun_RacingState :State<Sun>//Racing状态
{    
  private float enterTime;
  private Vector3 tempVec3;
  private bool audioPlay = false;
  private static Sun_RacingState instance;
  public static Sun_RacingState Instance ()
  {
    if (instance == null)
      instance = new Sun_RacingState ();
    
    return instance;
  }

  public override void Enter (Sun Entity)
  {
    //base.Enter (Entity);
    //Debug.Log(Time.time+ " enter racing");
    audioPlay = false;
    
    tempVec3=Entity.transform.position;
    tempVec3=Entity.rigidbody.velocity;
    tempVec3.z=MyValues.topSpeedX+6;//carGameObject.rigidbody.velocity.z+0.2f;
    tempVec3.z+=MyValues.addSpeedX;
    Entity.rigidbody.velocity=tempVec3;
    
    enterTime=Time.time;
  }

  public override void Execute (Sun Entity)
  {
    //base.Execute (Entity);
    GameObject carGameObject= GameObject.FindWithTag("Player");  
    float dis=carGameObject.transform.localPosition.z-Entity.transform.position.z;//+originalPosition.localPosition.z;  
    if(dis>32){
      Entity.GetFSM ().ChangeState(Sun_TrackState .Instance());
      return;
    }
    
    if(Time.time-enterTime>16){
      Entity.GetFSM ().ChangeState(Sun_RacingState .Instance());
      return;
    }
    else if(Time.time-enterTime > 3){
      //Debug.Log(Time.time+ " speedDown");
      audioPlay = false;
      Entity.loopframe(Entity.normalFrames);
      tempVec3.z=MyValues.topSpeedX;
      tempVec3.z+=MyValues.addSpeedX;
      Entity.rigidbody.velocity=tempVec3;
    }
    else{
      if(audioPlay == false&&Entity.isRendering==true){
        audioPlay = true;
        Audio audio= GameObject.FindWithTag("Audio").GetComponent<Audio>();  
        audio.PlayOneShot((int)sound_type.sun_pursue);
      }
      Entity.loopframe(Entity.trackFrames);
      //Debug.Log(Time.time+ " speedUp");
      tempVec3.z=MyValues.topSpeedX+3;
      tempVec3.z+=MyValues.addSpeedX;
      Entity.rigidbody.velocity=tempVec3;
    }
  }

  public override void Exit (Sun Entity)
  {
    //base.Exit (Entity);
  }

}

public class Sun_NothingState :State<Sun>//Nothing状态
{    
  //private float enterTime;
  
  private static Sun_NothingState instance;
  public static Sun_NothingState Instance ()
  {
    if (instance == null)
      instance = new Sun_NothingState ();
    
    return instance;
  }

  public override void Enter (Sun Entity)
  {
    //base.Enter (Entity);
    //TempValue.sunTrackDis=-1;
    //Entity.inNothingState=true;
    //Vector3 tempVec3=Entity.transform.position;
    //tempVec3.z=-150.0f;
    //Entity.transform.position=tempVec3;
  }

  public override void Execute (Sun Entity)
  {
    //base.Execute (Entity);
    Vector3 tempVec3=Entity.transform.position;
    tempVec3=Entity.rigidbody.velocity;
    tempVec3.z=0;//carGameObject.rigidbody.velocity.z+0.2f;
    Entity.rigidbody.velocity=tempVec3;
    
  }

  public override void Exit (Sun Entity)
  {
    //base.Exit (Entity);
    //TempValue.sunTrackDis=TempValue.dis;
  }
}

public class Sun_Covered_State :State<Sun>//the sun is covered by cloud迥カ諤
{  
  private float enterTime;
  private static Sun_Covered_State instance;
  public static Sun_Covered_State Instance ()
  {
    if (instance == null)
      instance = new Sun_Covered_State ();
    
    return instance;
  }

  public override void Enter (Sun Entity)
  {
    //base.Enter (Entity);
    Audio audio= GameObject.FindWithTag("Audio").GetComponent<Audio>();  
    audio.PlayOneShot((int)sound_type.sun_surprise);
    TempValue.bossCovered = true;
    TempValue.blockSunTimes++;
    //Vector3 tempVec3=Entity.transform.position;
    enterTime = Time.time;
    Vector3 tempVec3=Entity.rigidbody.velocity;
    tempVec3.z=MyValues.topSpeedX*0.0f;//carGameObject.rigidbody.velocity.z+0.2f;
    Entity.rigidbody.velocity=tempVec3;
    //GameObject coverCloud = GameObject.FindWithTag("PS_coverCloud");
    //coverCloud.renderer.enabled = true;
    Entity.childObject.gameObject.renderer.enabled =false;
    Entity.childObject.transform.GetChild(0).collider.enabled=false;
    Entity.childObject.gameObject.transform.GetComponentInChildren<Collider>().enabled = false;
    Entity.childObject.gameObject.transform.GetChild(0).gameObject.layer = 31;//nothing collider layer
  }

  public override void Execute (Sun Entity)
  {
    //base.Execute (Entity);
    Entity.loopframe();
    if(Time.time-enterTime>10){
      //Entity.GetFSM ().ChangeState(Sun_TrackState .Instance());
      //return;
    }
  }

  public override void Exit (Sun Entity)
  {
    TempValue.bossCovered = false;
    //GameObject CoverCloud = GameObject.FindWithTag("CoverCloud");
    //GameObject.Destroy(CoverCloud.gameObject);
    Entity.childObject.gameObject.renderer.enabled =true;
    Entity.childObject.transform.GetChild(0).collider.enabled=true;
    Entity.childObject.gameObject.transform.GetComponentInChildren<Collider>().enabled = true;
    Entity.childObject.gameObject.transform.GetChild(0).gameObject.layer = 19;//sun collider layer
    //base.Exit (Entity);
  }
}

public class Sun_Win_State :State<Sun>//the sun win
{  
  private float enterTime;
  private Vector3 tempVec3;
  private static Sun_Win_State instance;
  public static Sun_Win_State Instance ()
  {
    if (instance == null)
      instance = new Sun_Win_State ();
    
    return instance;
  }

  public override void Enter (Sun Entity)
  {
    Audio audio= GameObject.FindWithTag("Audio").GetComponent<Audio>();  
    //audio.PlayOneShot((int)sound_type.sun_laugh);
    audio.PlayLoop((int)sound_type.sun_laugh);
    enterTime = Time.time;
    tempVec3 = Entity.rigidbody.velocity;
    tempVec3.z = 30.0f;
    Entity.rigidbody.velocity=tempVec3;
    /*
    //base.Enter (Entity);
    //Vector3 tempVec3=Entity.transform.position;
    enterTime = Time.time;
    Vector3 tempVec3=Entity.rigidbody.velocity;
    tempVec3.z=MyValues.topSpeedX*0.0f;//carGameObject.rigidbody.velocity.z+0.2f;
    Entity.rigidbody.velocity=tempVec3;
    //GameObject coverCloud = GameObject.FindWithTag("PS_coverCloud");
    //coverCloud.renderer.enabled = true;
    Entity.childObject.gameObject.renderer.enabled =false;
    Entity.childObject.transform.GetChild(0).collider.enabled=false;
    */
  }

  public override void Execute (Sun Entity)
  {
    //base.Execute (Entity);
    Entity.loopframe(Entity.winFrames);
    if(Time.time-enterTime>2.0f){
      //Entity.GetFSM ().ChangeState(Sun_TrackState .Instance());
      //return;
      TempValue.gameover = true;
    }
  }

  public override void Exit (Sun Entity)
  {
    Audio audio= GameObject.FindWithTag("Audio").GetComponent<Audio>();  
    //audio.PlayOneShot((int)sound_type.sun_laugh);
    audio.StopLoop((int)sound_type.sun_laugh);
    //Entity.onlyOnce = true;
    /*
    //GameObject CoverCloud = GameObject.FindWithTag("CoverCloud");
    //GameObject.Destroy(CoverCloud.gameObject);
    Entity.childObject.gameObject.renderer.enabled =true;
    Entity.childObject.transform.GetChild(0).collider.enabled=true;
    //base.Exit (Entity);
    */
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 我可以为你解释一下cv:max33d成员赋值范例的概念。cv:max33d是一个模型,它能在给定的训练数据集上构建一个深度学习模型,以获得对给定输入的最佳预测结果。成员赋值范例是cv:max33d模型使用的一种方法,它可以根据训练数据集中的特征来计算每个样本的权重,以确定最佳预测结果。 ### 回答2: cv:max33d 成员是一个赋值范例,用于将一个变量赋值给另一个变量。赋值操作是计算机编程中常见的操作之一,用于将一个值或对象存储到变量中,以便在程序中使用。 cv:max33d 成员赋值范例可以有多种形式,具体取决于编程语言和变量类型。以下是一些常见的示例: 1. 基本类型变量的赋值: int a = 5; // 将整数值 5 赋给变量 a float b = 3.14; // 将浮点数值 3.14 赋给变量 b char c = 'A'; // 将字符 'A' 赋给变量 c 2. 引用类型变量的赋值: String str1 = "Hello"; // 将字符串 "Hello" 赋给变量 str1 List<Integer> list1 = new ArrayList<>(); // 创建一个整数列表,并将其赋给变量 list1 3. 对象间的赋值: Person person1 = new Person("John", 25); // 创建一个 Person 对象,并将其赋给变量 person1 Person person2 = person1; // 将 person1 的引用赋给变量 person2,它们指向同一个对象 总之,cv:max33d 成员赋值范例是用于将一个值或对象赋给一个变量的示例。这是一个基本的编程概念,对于理解和处理数据在计算机程序中的传递和操作非常重要。 ### 回答3: cv:max33d成员赋值范例可以通过以下方式进行。首先,在定义cv:max33d成员时,我们可以使用类似于字典的方式为它的属性赋值。例如: ``` cv:max33d{ name = "John", age = 25, gender = "male", height = 180 } ``` 在这个例子中,我们为cv:max33d的姓名(name)赋值为"John",年龄(age)赋值为25,性别(gender)赋值为"male",身高(height)赋值为180。 除了使用字典方式赋值,我们也可以使用函数调用的方式进行赋值。例如,创建一个函数setMember来给cv:max33d的属性赋值: ``` function setMember(member, name, age, gender, height) member.name = name member.age = age member.gender = gender member.height = height end cv:max33d = setMember(cv:max33d, "John", 25, "male", 180) ``` 在这个例子中,我们调用setMember函数,并将cv:max33d作为参数传入,同时传入姓名、年龄、性别和身高作为参数值进行赋值。 无论是使用字典方式赋值还是使用函数调用方式赋值,都可以根据实际的需求和代码组织结构,选择合适的方式进行成员赋值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值