Example #1
0
    public void SetupObjects(ConstrainedObjectEx co)
    {
        // Add all movers, assuming a list on the format "0.5*object1+0.5*object2"
        string[] moversStrings = co.moversName.Split('+');
        //co.movers.Clear();
        for (int i = 0; i < moversStrings.Length; i++)
        {
            ConstrainedObjectEx.ConstrainedObjectMover mover =
                new ConstrainedObjectEx.ConstrainedObjectMover();

            string[] strings = moversStrings[i].Split('*');
            if (strings.Length < 1 || strings.Length > 2)
            {
                Debug.LogError("[FXModuleConstrinPositionEx]: Every mover must be on the form '0.1*transformName' or 'transformName'");
                return;
            }
            mover.weight = 1.0;
            if (strings.Length == 1)
            {
                mover.transformName = strings[0];
            }
            else
            {
                mover.weight        = double.Parse(strings[0]);
                mover.transformName = strings[1];
            }

            co.movers.Add(mover);
        }

        if (co.movers.Count >= 1)
        {
            ObjectsList.Add(co);
        }
    }
Example #2
0
    public void TrackEx()
    {
        if (ObjectsList == null)
        {
            Debug.Log(string.Format("[TrackEx]: ObjectsList == null"));
            return;
        }

        for (int i = 0; i < ObjectsList.Count; i++)
        {
            ConstrainedObjectEx constrainedObject = ObjectsList[i];

            // Get the single target
            Transform targetTransform = base.part.FindModelTransform(constrainedObject.targetName);

            Vector3    position = new Vector3();
            Quaternion rotation = new Quaternion();
            for (int j = 0; j < constrainedObject.movers.Count; j++)
            {
                ConstrainedObjectEx.ConstrainedObjectMover mover = constrainedObject.movers[j];

                float   w     = (float)mover.weight;
                Vector3 scale = new Vector3(w, w, w);

                Transform moverTransform = base.part.FindModelTransform(mover.transformName);

                // Add the scaled vector to the sum
                position += Vector3.Scale(moverTransform.position, scale);

                // Just use any rotation
                rotation = moverTransform.rotation;
            }

            if (matchPosition)
            {
                targetTransform.position = position;
            }

            /*
             * if (matchRotation)
             *  transform.rotation = rotation;
             */
        }
    }