Exemple #1
0
    protected virtual void Awake()
    {
        myTransform   = transform;
        buildPosition = transform.position;
        hp            = new ConsumedAttribute(ConsumedAttributeName.Health, MaxHealth, 0, 0, 50, new AttributeModifier(), MaxHealth);
        GetComponent <Damagable>().damageHandler += Build_damageHandler;
        this.tag = Tags.Build;
        GameObject go;
        var        hudTextPoint = myTransform.Find("BuffHUDTextPoint");

        if (hudTextPoint != null)
        {
            go = hudTextPoint.gameObject;
        }
        else
        {
            go = new GameObject("BuffHUDTextPoint");
            go.transform.parent   = myTransform;
            go.transform.position = myTransform.position
                                    + new Vector3(0, .1f, 0);
            hudTextPoint = go.transform;
        }
        ht = (GameObject.Instantiate(
                  ResourceLoader.UIPrefabs.GetHurtText(),
                  go.transform.position, Quaternion.identity) as GameObject)
             .GetComponent <HurtText>();

        ht.InitailHUDText(hudTextPoint);

        var bloodPoint = myTransform.Find("BloodPoint");

        if (bloodPoint != null)
        {
            go = bloodPoint.gameObject;
        }
        else
        {
            go = new GameObject("BloodPoint");
            go.transform.parent   = myTransform;
            go.transform.position = myTransform.position
                                    + new Vector3(0, .5f, 0);
        }
        GameObject bb = GameObject.Instantiate(ResourceLoader.UIPrefabs.GetBuildBlood(), go.transform.position, Quaternion.identity) as GameObject;

        buildBlood = bb.GetComponent <BuildBlood>();
        buildBlood.InitialWithTarget(go.transform, this);
        if (myTransform.Find("DestroyFire") != null)
        {
            destroyFire = myTransform.Find("DestroyFire").gameObject;
        }
        SetNPCType(type);
    }
    //Monobehaviour life cycle
    protected virtual void Awake()
    {
        myTransform = transform;
        //設定角色控制器大小
        characterController = GetComponent <CharacterController>();
        SkinnedMeshRenderer skin = model.GetComponentInChildren <SkinnedMeshRenderer>();

        if (!ManualCharacterController)
        {
            characterController.stepOffset = 0.04f;
            characterController.slopeLimit = 45;
            characterController.height     = skin.bounds.size.y;
            characterController.radius     = (skin.bounds.size.x + skin.bounds.size.z) / 4;
            characterController.center     = Vector3.up * skin.bounds.size.y / 2;
            characterController.skinWidth  = 0.0001f;
        }
        BodyWidth  = characterController.bounds.size.x;
        BodyHeight = characterController.bounds.size.y;

        //設定浮動傷害顯視點
        buffs = new List <BuffSkill>();
        hts   = new List <HurtText>();
        for (int i = 0; i < 2; i++)
        {
            Transform hudTextPoint = new GameObject("HUDTextPoint").transform;
            hudTextPoint.parent   = myTransform;
            hudTextPoint.position = myTransform.position
                                    + new Vector3(Random.Range(BodyWidth * -1, BodyWidth),
                                                  Random.Range(BodyHeight / 2,
                                                               BodyHeight), 0);
            HurtText hurtText = (GameObject.Instantiate(
                                     ResourceLoader.UIPrefabs.GetHurtText(),
                                     hudTextPoint.position, Quaternion.identity) as GameObject)
                                .GetComponent <HurtText>();
            hurtText.gameObject.name = CharacterName + "_hurtText";
            hurtText.InitailHUDText(hudTextPoint);
            hts.Add(hurtText);
        }

        //設定浮動文字顯視點
        Transform buffHUDTextPoint = new GameObject("BuffHUDTextPoint").transform;

        buffHUDTextPoint.parent   = myTransform;
        buffHUDTextPoint.position = myTransform.position
                                    + new Vector3(0, BodyHeight, 0);
        buffHt = (GameObject.Instantiate(
                      ResourceLoader.UIPrefabs.GetHurtText(),
                      buffHUDTextPoint.position, Quaternion.identity) as GameObject)
                 .GetComponent <HurtText>();
        buffHt.InitailHUDText(buffHUDTextPoint);
        gameObject.AddComponent <Damagable>().damageHandler += Damage;

        //CreatePlaneForEargleEye();
        Mesh       mesh         = ResourceLoader.Utilities.GetCirclePlane();
        GameObject eargleEyeImg = new GameObject();

        eargleEyeImgTransform = eargleEyeImg.transform;
        eargleEyeImg.name     = "EargleEyeImg";
        eargleEyeImg.AddComponent <MeshFilter>().mesh = mesh;
        MeshRenderer eargleEyeImgMeshRenderer = eargleEyeImg.AddComponent <MeshRenderer>();

        eargleEyeImgMeshRenderer.materials = new Material[] {
            new Material(Shader.Find("Sprites/Default"))
        };
        eargleEyeImgMeshRenderer.materials[0].color =
            tag == Tags.Player ? Color.cyan :
            tag == Tags.Friend ? Color.green :
            tag == Tags.Enemy ? Color.yellow :
            Color.black;
        eargleEyeImgMeshRenderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
        eargleEyeImgMeshRenderer.shadowCastingMode    = UnityEngine.Rendering.ShadowCastingMode.Off;
        eargleEyeImg.layer                  = 12;
        eargleEyeImgTransform.parent        = myTransform;
        eargleEyeImgTransform.localPosition = Vector3.up * .5f;
        eargleEyeImgTransform.localScale    = Vector3.one * .4f;
    }