Example #1
0
    void CreateNegativeVector(string existingVectorName, string newVectorName)
    {
        bool vectorNamesMatch = newVectorName == existingVectorName;

        if (vectorNamesMatch)                   // a = -a
        {
            MakeVectorNegative(existingVectorName);
            return;
        }


        // b = -a

        SuperVector a = GetVectorByName(existingVectorName); // Does a exist?

        if (a == null)                                       // No
        {
            return;                                          // Get out. We can't do anything if we don't have a vector to clone.
        }
        RemoveNamedVector(newVectorName);                    // Removes "b" if it exists.

        SuperVector b = a.Clone(newVectorName);              // Let's clone "a" and assign it to b

        b.Negative();                                        // Let's negate "b" (flip it)
        AddNamedVector(b);                                   // Let's add the ne
    }
Example #2
0
    private void CreateOrUpdateSuperVector(SuperVector superVector)
    {
        bool  unnamed         = string.IsNullOrEmpty(superVector.vectorName);
        Color nextVectorColor = GetVectorColor(superVector.vectorName);

        if (unnamed)
        {
            DestroyLiveVectorIfItExists();
        }
        else
        {
            RemoveNamedVector(superVector.vectorName);
        }

        GameObject vectorGameObject = superVector.CreateGameObject();

        if (unnamed)
        {
            liveVector = vectorGameObject;
        }
        else
        {
            superVector.SetVectorColor(nextVectorColor);
            AddNamedVector(superVector);
        }
    }
Example #3
0
    private void SumAllVectors(string newVectorName, string vector1, string vector2, string vector3, string vector4, string vector5)
    {
        SuperVector superVector1 = GetVectorByName(vector1);

        if (superVector1 == null)
        {
            return;
        }

        SuperVector superVector2 = GetVectorByName(vector2);

        if (superVector2 == null)
        {
            return;
        }

        SuperVector superVector3 = GetVectorByName(vector3);
        SuperVector superVector4 = GetVectorByName(vector4);
        SuperVector superVector5 = GetVectorByName(vector5);

        SuperVector superVector = new SuperVector();

        superVector.vectorName = newVectorName;
        superVector.SetTo(superVector1);
        superVector.Add(superVector2);
        superVector.Add(superVector3);
        superVector.Add(superVector4);
        superVector.Add(superVector5);

        RemoveNamedVector(newVectorName);
        superVector.RefreshGameObject();
        AddNamedVector(superVector);
    }
Example #4
0
    void RemoveNamedVector(string vectorName, bool suppressErrors = true)
    {
        SuperVector matchingVector = GetVectorByName(vectorName, suppressErrors);

        if (matchingVector == null)
        {
            return;
        }
        RemoveVector(matchingVector);
    }
Example #5
0
    private SuperVector GetVectorByName(string vectorName, bool suppressErrors = false)
    {
        SuperVector superVector = superVectors.FirstOrDefault(test => test.vectorName == vectorName);

        if (superVector == null && !suppressErrors)
        {
            Debug.LogError($"We can't find a vector named \"{vectorName}\"!");
        }
        return(superVector);
    }
Example #6
0
    void OffsetVectorBy(string vectorName, double offsetX, double offsetY, double offsetZ)
    {
        SuperVector vector = GetVectorByName(vectorName);

        if (vector == null)
        {
            return;
        }

        vector.Offset(offsetX, offsetY, offsetZ);
    }
Example #7
0
    void HandleVectorCommand(string command, string vectorName)
    {
        SuperVector vector = GetVectorByName(vectorName);

        if (vector == null)
        {
            return;
        }

        HandleVectorCommand(command, vector);
    }
Example #8
0
    void MakeVectorNegative(string vectorName)
    {
        SuperVector matchingVector = GetVectorByName(vectorName);

        if (matchingVector == null)
        {
            return;
        }

        matchingVector.Negative();
    }
Example #9
0
    void ChangeVectorColor(string vectorName, string hexCode)
    {
        SuperVector matchingVector = GetVectorByName(vectorName);

        if (matchingVector == null)
        {
            return;
        }

        Color color;

        if (ColorUtility.TryParseHtmlString(hexCode, out color))
        {
            matchingVector.SetVectorColor(color);
        }
    }
Example #10
0
    void HandleVectorCommand(string command, SuperVector vector)
    {
        switch (command)
        {
        case "delete":
            DeleteVector(vector);
            break;

        case "hide":
            HideVector(vector);
            break;

        case "show":
            ShowVector(vector);
            break;
        }
    }
Example #11
0
    Color GetVectorColor(string vectorName)
    {
        SuperVector matchingVector = GetVectorByName(vectorName, true);

        if (matchingVector == null)
        {
            return(Color.black);
        }

        MeshRenderer[] coneMeshRenderers = matchingVector.VectorGameObject.GetComponentsInChildren <MeshRenderer>();
        foreach (MeshRenderer meshRenderer in coneMeshRenderers)
        {
            return(meshRenderer.material.color);
        }

        return(Color.black);
    }
Example #12
0
    void MoveVectorTo(string vector1, string vector2)
    {
        SuperVector superVector1 = GetVectorByName(vector1);

        if (superVector1 == null)
        {
            return;
        }

        SuperVector superVector2 = GetVectorByName(vector2);

        if (superVector2 == null)
        {
            return;
        }

        // If we are here, we know that both superVector1 and superVector2 are both good.
        superVector2.MoveTailTo(superVector1.X, superVector1.Y, superVector1.Z);
    }
Example #13
0
    private void ExecuteCommandLine(string text)
    {
        SuperVector superVector = SuperVector.Create(text);

        if (superVector != null)
        {
            CreateOrUpdateSuperVector(superVector);
            return;
        }

        SetColor setColor = SetColor.Create(text);

        if (setColor != null)
        {
            ChangeVectorColor(setColor.vectorName, setColor.hexCode);
            return;
        }

        SetNamedColor setNamedColor = SetNamedColor.Create(text);

        if (setNamedColor != null)
        {
            string hexCode;
            if (colorLookups.ContainsKey(setNamedColor.colorName))
            {
                hexCode = colorLookups[setNamedColor.colorName];
                ChangeVectorColor(setNamedColor.vectorName, hexCode);
            }
            else
            {
                Debug.LogError($"\"{setNamedColor.colorName}\" needs to be defined first!!!");
            }
            return;
        }

        DefineColor defineColor = DefineColor.Create(text);

        if (defineColor != null)
        {
            DefineColorName(defineColor.colorName, defineColor.hexCode);
            return;
        }

        MoveVector moveVector = MoveVector.Create(text);

        if (moveVector != null)
        {
            MoveVectorTo(moveVector.vector1, moveVector.vector2);
            return;
        }

        SumVectors sumVectors = SumVectors.Create(text);

        if (sumVectors != null)
        {
            SumAllVectors(sumVectors.newVectorName, sumVectors.vector1, sumVectors.vector2, sumVectors.vector3, sumVectors.vector4, sumVectors.vector5);
            return;
        }

        NegativeVector negativeVector = NegativeVector.Create(text);

        if (negativeVector != null)
        {
            MakeVectorNegative(negativeVector.vectorName);
            return;
        }

        AssignNegativeVector assignNegativeVector = AssignNegativeVector.Create(text);

        if (assignNegativeVector != null)
        {
            CreateNegativeVector(assignNegativeVector.existingVectorName, assignNegativeVector.newVectorName);
            return;
        }

        VectorCommand vectorCommand = VectorCommand.Create(text);

        if (vectorCommand != null)
        {
            HandleVectorCommand(vectorCommand.command, vectorCommand.vectorName);
            return;
        }
        OffsetVector offsetVector = OffsetVector.Create(text);

        if (offsetVector != null)
        {
            OffsetVectorBy(offsetVector.vectorName, offsetVector.offsetX, offsetVector.offsetY, offsetVector.offsetZ);
            return;
        }
    }
Example #14
0
 void ShowVector(SuperVector vector)
 {
     vector.CreateGameObject();
 }
Example #15
0
 void HideVector(SuperVector vector)
 {
     vector.DestroyGameObject();
 }
Example #16
0
 private void RemoveVector(SuperVector vector)
 {
     superVectors.Remove(vector);
     vector.DestroyGameObject();
 }
Example #17
0
 void DeleteVector(SuperVector vector)
 {
     RemoveVector(vector);
 }
Example #18
0
 void AddNamedVector(SuperVector superVector)
 {
     superVectors.Add(superVector);
 }