コード例 #1
0
    /// <summary>
    /// Changes the length of the drake by modifying the last bone index
    /// </summary>
    /// <param name='newCount'>
    /// New bone count (superior bones will be disabled)
    /// </param>
    private void ChangeBoneCount(int newCount)
    {
        // Change index of last bone
        currentBoneCount = Mathf.Clamp(newCount, BONE_COUNT_MIN, bones.Length);

        // Update line renderer
        CreateBodyLine();

        // Update scales
        int cnt = 0;

        for (int i = 0; i < scales.Length; ++i)
        {
            DrakeScale s = scales[i];
            if (s.boneRef.index < currentBoneCount && i != 0)
            {
                if (!Helper.IsActive(scales[i].gameObject))
                {
                    Helper.SetActive(scales[i].gameObject, true);
                    if (scales[i].glowRef != null)
                    {
                        Helper.SetActive(scales[i].glowRef, true);
                    }
                    s.Shine();
                    // Note : they will be updated in their Start() method
                    //s.UpdateColorDistanceAutonomy();
                }
                else
                {
                    s.UpdateColorDistanceAutonomy();
                }
                ++cnt;
            }
            else
            {
                Helper.SetActive(scales[i].gameObject, false);
                if (scales[i].glowRef != null)
                {
                    Helper.SetActive(scales[i].glowRef, false);
                }
            }
        }

        currentScaleCount = cnt;

        // Update tail position
        DrakeBone lastBone = bones [currentBoneCount - 1];

        tail.transform.position = lastBone.pos;
    }
コード例 #2
0
 void OnTriggerEnter(Collider other)
 {
     if (!powered)
     {
         DrakeScale ds = other.GetComponent <DrakeScale>();
         if (ds != null)
         {
             if (ds.ColorLevel > 0)
             {
                 Power();
                 if (poweredCount == stars.Count)
                 {
                     ds.drakeRef.Maximize();
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: SwappableStar.cs プロジェクト: Yakka/Aku
    void OnTriggerEnter(Collider other)
    {
        if (!swapping)
        {
            DrakeScale drakeScale = other.GetComponent <DrakeScale>();
            if (drakeScale != null && drakeScale.HasMoonPaint)
            {
                Drake drake = drakeScale.drakeRef;

                if (drake.LastTouchedStar == null)
                {
                    // First star selected !
                    if (halo != null)
                    {
                        halo.SetON(true);
                    }
                    drake.LastTouchedStar = gameObject;
                }
                else
                {
                    SwappableStar otherStar =
                        drake.LastTouchedStar.GetComponent <SwappableStar>();

                    // If the star exist and is different
                    if (otherStar != null && otherStar != this)
                    {
                        drake.LastTouchedStar = null;

                        // Second star selected, swapping !
                        Swap(otherStar, true);
                        SoundLevel2.Instance.SwapStar();
                    }
                }
            }
        }
    }
コード例 #4
0
    void Start()
    {
        #region "Check parameters"

        targetSpeed      = speedLimit.min;
        speed            = targetSpeed;
        wavingPhaseSpeed = wavingPhaseSpeedMax;
        // Default parameters
        if (currentBoneCount <= BONE_COUNT_MIN)
        {
            currentBoneCount = BONE_COUNT_MIN;
        }

        #endregion
        #region "Create bones"

        // Pre-allocate the maximum number of bones
        bones     = new DrakeBone[BONE_COUNT_MAX];
        bones [0] = new DrakeBone(transform.position, 0);
        for (int i = 1; i < bones.Length; i++)
        {
            DrakeBone prev = bones [i - 1];

            // Align as a straight line
            DrakeBone bone = new DrakeBone(
                prev.pos.x - BONE_SPACING, prev.pos.y, prev.pos.z, i);
            bone.angleRad = 0;

            // Linking
            bone.drakeRef = this;
            bone.parent   = prev;
            prev.child    = bone;

            bones [i] = bone;
        }

        #endregion
        #region "Create body line"

        CreateBodyLine();

        #endregion
        #region "Create scales"

        // Pre-allocate the maximum number of scales
        // (only a subset of them will be active)
        scales = new DrakeScale[SCALE_COUNT_MAX];
        float t_step = 1.0f / (float)scales.Length;

        for (int i = 0; i < scales.Length; ++i)
        {
            float t = t_step * i;

            // Get the bone where we will attach the scale
            DrakeBone bone = GetBoneFromParametric(t);

            // Compute a random scale ID
            int prefabIndex = UnityEngine.Random.Range(0, scalePrefabs.Length - 1);

            // Create scale
            GameObject scaleObject = Instantiate(
                scalePrefabs [prefabIndex],
                new Vector3(bone.pos.x, bone.pos.y, bone.pos.z),
                Quaternion.identity
                ) as GameObject;

            // Set its color
            //Material scaleMaterial = new Material (Shader.Find ("Diffuse"));
            //scaleMaterial.color = Color.black;
            MeshRenderer meshRenderer = scaleObject.GetComponent <MeshRenderer> ();
            meshRenderer.material = scaleMaterial;

            // Add scripts
            scaleObject.AddComponent("DrakeScale");
            scaleObject.AddComponent("PainterBehavior");

            // Add glow
            GameObject glowObj = null;
            if (i != 0)              // because the first scale is... well, not used (See below).
            {
                glowObj = Instantiate(glowPrefab) as GameObject;
            }

            // Get scale script and init some of its variables
            DrakeScale scaleScript = scaleObject.GetComponent <DrakeScale> ();
            scaleScript.boneRef            = bone;
            scaleScript.drakeRef           = this;
            scaleScript.glowRef            = glowObj;
            scaleScript.parametricPosition = t;
            scaleScript.indexedPosition    = i;
            //scaleScript.materialRef = scaleMaterial;
            scales[i] = scaleScript;

            // Fix scale size
            const float scaleFix = 1.15f;
            scaleObject.transform.localScale = new Vector3(scaleFix, scaleFix, scaleFix);

            // Set scale as child of the drake : not useful for now
        }

        // Disable first scale because it overlaps on the head
        // TODO dirty code, try to do this more cleanly
        Helper.SetActive(scales[0].gameObject, false);

        #endregion
        #region "Create tail"

        DrakeBone lastBone = bones [currentBoneCount - 1];
        tail = Instantiate(
            tailPrefab,
            new Vector3(lastBone.pos.x, lastBone.pos.y, lastBone.pos.z),
            Quaternion.identity
            ) as GameObject;

        // Set tail mesh color
        Material tailMaterial = new Material(Shader.Find("Diffuse"));
        tailMaterial.color = Color.black;
        tail.GetComponent <MeshRenderer>().material = tailMaterial;

        #endregion

        ChangeBoneCount(currentBoneCount);
        startBoneCount = currentBoneCount;
        //startScaleCount = currentScaleCount;

        if (Settings.trailerMode)
        {
            ChangeBoneCount(BONE_COUNT_MAX);
        }
    }