Beispiel #1
0
 public void updateAllStates(WorkspaceState prevState, float t)
 {
     // t is used as the interpolation parameter.
     foreach (VisualElement element in this.elementStates.Keys)
     {
         VisualElementState curElementState = elementStates[element];
         if (prevState.ElementExists(element))
         {
             // Interpolate between states
             VisualElementState prevElementState = prevState.elementStates[element];
             prevElementState.BlendStates(curElementState, t);
         }
         else
         {
             // Pop in from zero scale
             VisualElementState pseudoState = new VisualElementState(curElementState);
             pseudoState.SetStateScale(Vector3.zero);
             pseudoState.BlendStates(curElementState, t);
         }
     }
     foreach (VisualElement element in prevState.elementStates.Keys)
     {
         if (!this.ElementExists(element))
         {
             // Disable
             VisualElementState prevElementState = prevState.elementStates[element];
             VisualElementState pseudoState      = new VisualElementState(prevElementState);
             pseudoState.SetStateScale(Vector3.zero);
             prevElementState.BlendStates(pseudoState, t);
         }
     }
 }
Beispiel #2
0
 public VisualElementState(VisualElementState newState)
 {
     this.element_       = newState.GetStateElement();
     this.statePosition_ = newState.GetStatePosition();
     this.stateScale_    = newState.GetStateScale();
     this.stateRotation_ = newState.GetStateRotation();
     this.stateMaterial_ = newState.GetStateMaterial();
 }
Beispiel #3
0
 public WorkspaceState(WorkspaceState prevState)
 {
     this.elementStates = new Dictionary <VisualElement, VisualElementState>();
     foreach (VisualElement element in prevState.elementStates.Keys)
     {
         VisualElementState elementState    = prevState.elementStates[element];
         VisualElementState newElementState = new VisualElementState(elementState);
         this.elementStates.Add(element, newElementState);
     }
 }
Beispiel #4
0
 public void SetColorSelected(Material mat)
 {
     foreach (VisualElement element in this.selectedVisualElements_)
     {
         // set the material for state & the gameobject
         VisualElementState state = this._curState.elementStates[element];
         state.SetStateMaterial(mat);
         element.GetComponent <Renderer>().material.CopyPropertiesFromMaterial(mat);
     }
 }
Beispiel #5
0
        public void UpdateState()
        {
            VisualElementState state = this.workspace.GetCurrentState().elementStates[this];

            state.SetStatePosition(this.gameObject.transform.position);
            state.SetStateScale(this.gameObject.transform.lossyScale);
            state.SetStateRotation(this.gameObject.transform.rotation);
            Material mat = new Material(this.gameObject.GetComponent <Renderer>().material);

            state.SetStateMaterial(mat);
        }
Beispiel #6
0
        // This functions updates/adds new element as a state in the workspace.
        public void AddState(VisualElement element)
        {
            VisualElementState newState = new VisualElementState(element);

            if (!this.ElementExists(element))
            {
                elementStates.Add(element, newState);
            }
            else
            {
                elementStates[element] = newState;
            }

            Debug.Log("Element count: " + elementStates.Count);
        }
Beispiel #7
0
        // This function assigns a blend of this state with another.
        public void BlendStates(VisualElementState secondState, float t)
        {
            // A t-value of 0 will assign the state stored in the caller.
            // A t-value of 1 will assign the state passed into the function.
            // A t-value between 0 and 1 will assign a blend of the two states.
            if (t >= 0 && t <= 1)
            {
                // Interpolate the transform values and assign them.
                Vector3    secondPosition = secondState.GetStatePosition();
                Vector3    secondScale    = secondState.GetStateScale();
                Quaternion secondRotation = secondState.GetStateRotation();
                Vector3    lerpedPosition = Vector3.Lerp(this.statePosition_, secondPosition, t);
                Vector3    lerpedScale    = Vector3.Lerp(this.stateScale_, secondScale, t);
                Quaternion lerpedRotation = Quaternion.Slerp(this.stateRotation_, secondRotation, t);
                element_.gameObject.transform.position   = lerpedPosition;
                element_.gameObject.transform.localScale = lerpedScale;
                element_.gameObject.transform.rotation   = lerpedRotation;

                // Lerp the main colors of each material and assign it.
                Renderer rend = element_.GetComponent <Renderer>();
                rend.material.Lerp(this.stateMaterial_, secondState.GetStateMaterial(), t);
            }
        }