Пример #1
0
    void SelectShape(RaycastHit[] hits)
    {
        Array.Sort(hits, delegate(RaycastHit hit1, RaycastHit hit2){
            return(hit1.distance.CompareTo(hit2.distance));
        });


        for (int i = 0; i < hits.Length; i++)
        {
            GameObject go = hits [i].transform.gameObject;
            ShapeAsset sa = go.GetComponentInParent <ShapeAsset> ();
            if (sa != null)
            {
                Debug.Log(sa.gameObject.name);
                Events.OnShapeSelected(sa);
                Game.Instance.board.selectedShape = sa;
                newRotation  = sa.transform.localEulerAngles;
                newPosition  = sa.transform.localPosition;
                lastRotation = sa.transform.localEulerAngles;
                lastPosition = sa.transform.localPosition;
                Events.CloseSubMenu();
                SetState(Board.ActionStates.DRAGGING);
                break;
            }
        }
    }
Пример #2
0
    public void Move(Vector3 moveVector)
    {
        if (GetState() == Board.ActionStates.TRANSFORMING)
        {
            return;
        }

        if (unmoved)
        {
            unmoved = false;
        }

        ShapeAsset selectedShape = Game.Instance.board.selectedShape;

        SetState(Board.ActionStates.TRANSFORMING);
        lastPosition = selectedShape.transform.localPosition;

        Vector3 pos = selectedShape.transform.localPosition;

        pos += moveVector;
        if (pos.y < 0)
        {
            pos.y = 0;
        }
        newPosition = pos;
        Invoke("Done", 0.5f);
    }
Пример #3
0
    public void Rotate(int qty)
    {
        //print ("ROTA");
        if (GetState() == Board.ActionStates.TRANSFORMING)
        {
            return;
        }

        if (unmoved)
        {
            unmoved = false;
        }

        ShapeAsset selectedShape = Game.Instance.board.selectedShape;

        SetState(Board.ActionStates.TRANSFORMING);
        lastRotation = selectedShape.transform.localEulerAngles;

        Vector3 rot = selectedShape.transform.localEulerAngles;

        if (qty < 0 && (lastRotation.y < 1f || lastRotation.y > 359f))
        {
            rot = new Vector3(lastRotation.x, 359f, lastRotation.z);
            selectedShape.transform.localEulerAngles = rot;
            rot.y += qty + 1;
        }
        else
        {
            rot.y += qty;
        }
        newRotation = rot;
        Invoke("Done", 0.5f);
    }
Пример #4
0
        private ShapeAsset CreateShapeAsset()
        {
            string extension = ".asset";
            string path      = EditorUtility.SaveFilePanel("Create New Shape Asset", Application.dataPath, "New Shape" + extension, "asset");

            if (path.Length == 0)
            {
                return(null);
            }


            int    filePos = path.LastIndexOf(extension);
            int    namePos = path.LastIndexOf('/') + 1;
            string name    = path.Substring(namePos, filePos - namePos);

            path = path.Substring(path.LastIndexOf("Assets"));

            ShapeAsset newShape = ShapeAsset.CreateInstance(typeof(ShapeAsset)) as ShapeAsset;

            newShape.name = name;
            AssetDatabase.CreateAsset(newShape, path);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = newShape;

            return(newShape);
        }
Пример #5
0
        public static Shape CreateShapeObj(ShapeAsset shapeAsset, GameObject parent = null)
        {
            var s = CreateShapeObj(shapeAsset.name);

            s.ShapeAsset = shapeAsset;

            return(s);
        }
Пример #6
0
    public void AddShape(ShapeAsset sa, int id)
    {
        ShapesData sd = new ShapesData();

        sd.id    = id;
        sd.asset = sa;
        all.Add(sd);
    }
Пример #7
0
    void Done()
    {
        SetState(Board.ActionStates.DONE);
        ShapeAsset selectedShape = Game.Instance.board.selectedShape;

        selectedShape.transform.localEulerAngles = newRotation;
        selectedShape.transform.localPosition    = newPosition;
        if (Game.Instance.board.mechanicState == Board.MechanicStates.INTEGRAR)
        {
            Game.Instance.integrationManager.CheckIntegration();
        }
    }
Пример #8
0
    void Snap()
    {
        Vector3 step = Game.Instance.levelManager.GetSnap();

        if (Game.Instance.board.mechanicState == Board.MechanicStates.COMBINAR)
        {
            step = Game.Instance.combinarManager.step;
        }
        newPosition = new Vector3(Mathf.Round(newPosition.x / step.x) * step.x, Mathf.Round(newPosition.y / step.y) * step.y, Mathf.Round(newPosition.z / step.z) * step.z);
        ShapeAsset selectedShape = Game.Instance.board.selectedShape;

        selectedShape.transform.localPosition = newPosition;
        CheckCollision();
    }
Пример #9
0
    void CheckCollision()
    {
        ShapeAsset selectedShape = Game.Instance.board.selectedShape;

        if (selectedShape != null)
        {
            ShapeCollider[] scs = selectedShape.GetComponentsInChildren <ShapeCollider> ();
            foreach (ShapeCollider sc in scs)
            {
                if (sc.undoIt)
                {
                    UndoLastTransform();
                    return;
                }
            }
            Invoke("Done", 0.5f);
        }
    }
Пример #10
0
 void OnShapeSelected(ShapeAsset sa)
 {
     foreach (Image t in toColirize)
     {
         if (sa == null)
         {
             t.color = Color.grey;
         }
         else if (Game.Instance.board.selectedShape.childs.Count == 0 && type == types.BREAK)
         {
             t.color = Color.grey;
         }
         else
         {
             t.color = sa.color;
         }
     }
 }
Пример #11
0
    void OnTriggerExit(Collider other)
    {
        ShapeCollider sc = other.GetComponent <ShapeCollider> ();

        if (sc == null)
        {
            return;
        }
        ShapeAsset otherShapeAsset = sc.shapeAsset;

        if (otherShapeAsset == null)
        {
            return;
        }
        if (shapeAsset == otherShapeAsset)
        {
            return;
        }
        undoIt = false;
    }
Пример #12
0
    void OnTriggerEnter(Collider other)
    {
        ShapeCollider sc = other.GetComponent <ShapeCollider> ();

        if (sc == null)
        {
            return;
        }
        ShapeAsset otherShapeAsset = sc.shapeAsset;

        if (otherShapeAsset == null)
        {
            return;
        }
        if (shapeAsset == otherShapeAsset)
        {
            return;
        }
        Game.Instance.shapeMove.UndoLastTransform();
        undoIt = true;
    }
Пример #13
0
    public void UndoLastTransform()
    {
        if (GetState() == Board.ActionStates.DRAGGING)
        {
            return;
        }
        SetState(Board.ActionStates.DONE);
        CancelInvoke();
        ShapeAsset selectedShape = Game.Instance.board.selectedShape;

        if (unmoved)
        {
            selectedShape.transform.localPosition = GetEmptySpace();
            lastPosition = selectedShape.transform.localPosition;
        }
        else
        {
            selectedShape.transform.localEulerAngles = lastRotation;
            selectedShape.transform.localPosition    = lastPosition;
        }
    }
Пример #14
0
    void Update()
    {
        if (GetState() == Board.ActionStates.TRANSFORMING)
        {
            ShapeAsset selectedShape = Game.Instance.board.selectedShape;
            selectedShape.transform.localEulerAngles = Vector3.Lerp(selectedShape.transform.localEulerAngles, newRotation, 0.25f);
            selectedShape.transform.localPosition    = Vector3.Lerp(selectedShape.transform.localPosition, newPosition, 0.25f);
        }


        if (GetState() == Board.ActionStates.DRAGGING)
        {
            if (offsetDone)
            {
                newPosition = mousePos + offset;
                //newPosition.y = 0f;
                ShapeAsset selectedShape = Game.Instance.board.selectedShape;
                selectedShape.transform.localPosition    = newPosition;
                selectedShape.transform.localEulerAngles = newRotation;
            }

            if (Game.Instance.inputManager.mousePressed)
            {
                CheckMousePos(Game.Instance.inputManager.hits);
            }
            else if (!Game.Instance.inputManager.mousePressed)
            {
                Snap();
                SetState(Board.ActionStates.IDLE);
                offsetDone = false;
            }
        }
        else
        {
            if (Game.Instance.inputManager.mousePressed)
            {
                SelectShape(Game.Instance.inputManager.hits);
            }
        }
    }
Пример #15
0
 void SelectNewShape(int id)
 {
     if (mechanicState == MechanicStates.INTEGRAR)
     {
         ShapesData shapeData  = Game.Instance.shapesManager.GetByID(id);
         ShapeAsset shapeAsset = Instantiate(shapeData.asset);
         shapeAsset.transform.SetParent(compararContainer);
         shapeAsset.transform.localScale = Vector3.one;
         shapeAsset.SetColor(Game.Instance.shapesManager.GetFreeColor(compararAll));
         compararAll.Add(shapeAsset);
         selectedShape = shapeAsset;
     }
     else if (mechanicState == MechanicStates.COMBINAR)
     {
         ShapesData shapeData  = Game.Instance.shapesManager.GetCombinarByID(id);
         ShapeAsset shapeAsset = Instantiate(shapeData.asset);
         shapeAsset.transform.SetParent(combinarContainer);
         shapeAsset.transform.localScale = Vector3.one;
         shapeAsset.SetColor(Color.white);
         combinarAll.Add(shapeAsset);
         selectedShape = shapeAsset;
     }
 }
Пример #16
0
    public Vector3 GetEmptySpace()
    {
        if (Game.Instance.board.compararAll.Count == 1)
        {
            return(defaultSpace);
        }
        ShapeAsset selectedShape = Game.Instance.board.selectedShape;
        float      z             = empty_id_z * selectedShape.size.z;

        empty_id_z++;
        if (z > empty_size)
        {
            empty_id_z = 0;
            empty_id_x++;
        }
        float x = empty_id_x * selectedShape.size.x;

        if (x > empty_size)
        {
            empty_id_x = 0;
        }
        Debug.Log(empty_id_x + " : " + empty_id_z);
        return(new Vector3(defaultSpace.x + x, 0, defaultSpace.z + z));
    }
Пример #17
0
        public override void OnInspectorGUI()
        {
            GUILayout.Space(5.0f);

            EditorGUILayout.BeginHorizontal();
            ShapeAsset shapeAsset = (ShapeAsset)EditorGUILayout.ObjectField(
                "Shape", _currentPath.shapeAsset, typeof(ShapeAsset), false);

            _currentPath.shapeAsset = shapeAsset;

            if (shapeAsset != null)
            {
                if (GUILayout.Button("Edit", GUILayout.Width(60)))
                {
                    ShapeEditorWindow.Edit(shapeAsset);
                }
            }
            else
            {
                if (GUILayout.Button("Create", GUILayout.Width(60)))
                {
                    ShapeAsset newShapeAsset = CreateShapeAsset();
                    if (newShapeAsset != null)
                    {
                        _currentPath.shapeAsset = newShapeAsset;
                    }
                }
            }

            EditorGUILayout.EndHorizontal();

            GUILayout.Space(15);

            EditorGUI.BeginChangeCheck();

            Vector2 scale        = EditorGUILayout.Vector2Field("Scale", _currentPath.scale);
            int     subdivisions = EditorGUILayout.IntField("Subdivisions", Mathf.Clamp(_currentPath.subdivisions, 1, 100));
            float   uvResolution = EditorGUILayout.Slider("Uv resolution", _currentPath.uvResolution, 0.2f, 10.0f);
            bool    loopCurve    = EditorGUILayout.Toggle("Loop curve", _currentPath.loopCurve);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(_currentPath, "Modify Path Settings");
                EditorUtility.SetDirty(_currentPath);
                _currentPath.scale        = scale;
                _currentPath.subdivisions = subdivisions;
                _currentPath.uvResolution = uvResolution;
                _currentPath.loopCurve    = loopCurve;
            }

            GUILayout.Space(20);

            for (int i = 0; i < _currentPath.pathData.Length; i++)
            {
                if (PathPointEditor.selectedId == i)
                {
                    PathPointEditor.EditPointGUI(i);
                }
            }

            if (GUILayout.Button("Add Point"))
            {
                Undo.RecordObject(_currentPath, "Add point");
                EditorUtility.SetDirty(_currentPath);
                _currentPath.pathData.AddPoint(_currentPath.transform.position);
                SceneView.RepaintAll();
            }

            if (GUILayout.Button("Remove Point") && _currentPath.pathData.Length > 1)
            {
                Undo.RecordObject(_currentPath, "Remove point");
                EditorUtility.SetDirty(_currentPath);
                _currentPath.pathData.RemovePoint(PathPointEditor.selectedId);
                SceneView.RepaintAll();
            }

            GUILayout.Space(20);

            _autoGenerateRoad = EditorGUILayout.Toggle("Auto Generate", _autoGenerateRoad);

            if (!_autoGenerateRoad && GUILayout.Button("Generate Road"))
            {
                _currentPath.UpdatePath();
                SceneView.RepaintAll();
            }
        }
Пример #18
0
    public static void DrawShapeEditor(Shape shape)
    {
        bool newIsPolyColliderGenerated = shape.CreatePolyCollider;

        EditorGUI.BeginChangeCheck();
        newIsPolyColliderGenerated = EditorGUILayout.Toggle("Create Poly Collider", newIsPolyColliderGenerated);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(shape.dataContainerObject, "Edit Shape");

            shape.CreatePolyCollider = newIsPolyColliderGenerated;
            SetDataDirty(shape);
        }

        ShapePolyDimension newPolyDimension = shape.ShapeData.PolyDimension;
        ShapeType          newType          = shape.ShapeData.ShapeType;
        Vector2            newOffset        = shape.ShapeData.ShapeOffset;
        Vector2            newSize          = shape.ShapeData.ShapeSize;
        ShapeAsset         shapeAsset       = shape.ShapeAsset;
        bool newIsPolyClosed = shape.ShapeData.IsPolygonStrokeClosed;


        EditorGUI.BeginChangeCheck();
        GUILayout.Label("Shape", EditorStyles.boldLabel);
        if (shape.ShapeRenderer)
        {
            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.ObjectField("Rendered by", shape.ShapeRenderer, typeof(ShapeRenderer), true);
            EditorGUI.EndDisabledGroup();
        }
        else
        {
            EditorGUILayout.HelpBox("No shape renderer found. This shape will not be rendered until it is parented under a GameObject with a ShapeRenderer component attached, or a ShapeRenderer component is attached to this object", MessageType.Warning);
        }
        shapeAsset = (ShapeAsset)EditorGUILayout.ObjectField("Shape Asset", shapeAsset, typeof(ShapeAsset), false);

        GUILayout.Label("Shape", EditorStyles.boldLabel);
        newType = (ShapeType)EditorGUILayout.EnumPopup("Type", newType);
        if (newType == ShapeType.Polygon)
        {
            newPolyDimension = (ShapePolyDimension)EditorGUILayout.EnumPopup("Dimension", newPolyDimension);
            newIsPolyClosed  = EditorGUILayout.Toggle("Is Closed", newIsPolyClosed);
        }

        if (newType == ShapeType.Circle ||
            newType == ShapeType.Rectangle)
        {
            newOffset = EditorGUILayout.Vector2Field("Offset", newOffset);
            newSize   = EditorGUILayout.Vector2Field("Size", newSize);
        }

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(shape.dataContainerObject, "Edit Shape");

            shape.ShapeAsset = shapeAsset;

            ShapeType oldType = shape.ShapeData.ShapeType;

            if (newType != oldType)
            {
                shape.ShapeData.ShapeType = newType;
                if (newType == ShapeType.Polygon)
                {
                    List <ShapeVertexInfo> vertexList = new List <ShapeVertexInfo>();
                    if (oldType == ShapeType.Circle)
                    {
                        ShapeVertexInfoUtils.GetCircleVertexInfoList(shape.ShapeData, vertexList, 0);
                    }
                    if (oldType == ShapeType.Rectangle)
                    {
                        ShapeVertexInfoUtils.GetRectVertexInfoList(shape.ShapeData, vertexList, 0);
                    }
                    shape.ShapeData.AddFromVertexInfoList(vertexList);
                }
                else if (newType == ShapeType.Circle || newType == ShapeType.Rectangle)
                {
                    if (oldType == ShapeType.Polygon)
                    {
                        Bounds bounds = new Bounds();
                        for (int i = 0; i < shape.ShapeData.GetPolyPointCount(); i++)
                        {
                            Vector3 p = shape.ShapeData.GetPolyPosition(i);
                            if (i == 0)
                            {
                                bounds = new Bounds(p, Vector3.zero);
                            }
                            else
                            {
                                bounds.Encapsulate(p);
                            }
                        }

                        shape.ShapeData.ShapeSize = bounds.size;
                    }
                }
            }

            if (shape.ShapeData.ShapeType != ShapeType.Polygon)
            {
                shape.ShapeData.ClearPolyPoints();
            }

            shape.ShapeData.PolyDimension         = newPolyDimension;
            shape.ShapeData.IsPolygonStrokeClosed = newIsPolyClosed;
            shape.ShapeData.ShapeSize             = newSize;
            shape.ShapeData.ShapeOffset           = newOffset;

            SetDataDirty(shape);
        }
    }
Пример #19
0
 void Awake()
 {
     shapeAsset = GetComponentInParent <ShapeAsset> ();
 }
 private void OnEnable()
 {
     ValidateData();
     shapeAsset = target as ShapeAsset;
 }