Exemplo n.º 1
0
    void                 OnSceneGUI()
    {
        Ferr2D_Path path      = (Ferr2D_Path)target;
        GUIStyle    iconStyle = new GUIStyle();

        iconStyle.alignment = TextAnchor.MiddleCenter;

        // if this was an undo, refresh stuff too
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
                path.UpdateDependants();
                return;
            }
        }

        // setup undoing things
                #if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
        Undo.RecordObject(target, "Modified Path");
                #else
        Undo.SetSnapshotTarget(target, "Modified Path");
        Undo.CreateSnapshot();
                #endif

        // draw and interact with all the path handles
        DoHandles(path, iconStyle);

        // draw the path line
        DoPath(path);

        // do adding verts in when the shift key is down!
        if (Event.current.shift)
        {
            DoShiftAdd(path, iconStyle);
        }

        // update everything that relies on this path, if the GUI changed
        if (GUI.changed)
        {
                        #if (UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
            Undo.RegisterSnapshot();
                        #endif
            path.UpdateDependants();
            EditorUtility.SetDirty(target);
        }
    }
Exemplo n.º 2
0
    public override void OnInspectorGUI()
    {
                #if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
        Undo.RecordObject(target, "Modified Path");
                #else
        Undo.SetSnapshotTarget(target, "Modified Path");
                #endif

        Ferr2D_Path path = (Ferr2D_Path)target;

        path.closed = EditorGUILayout.Toggle("Closed", path.closed);

        // display the path verts list info
        showVerts             = EditorGUILayout.Foldout(showVerts, "Path Vertices");
        EditorGUI.indentLevel = 2;
        if (showVerts)
        {
            int size = EditorGUILayout.IntField("Count: ", path.pathVerts.Count);
            while (path.pathVerts.Count > size)
            {
                path.pathVerts.RemoveAt(path.pathVerts.Count - 1);
            }
            while (path.pathVerts.Count < size)
            {
                path.pathVerts.Add(new Vector2(0, 0));
            }
        }
        // draw all the verts! Long list~
        for (int i = 0; showVerts && i < path.pathVerts.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("#" + i, GUILayout.Width(60));
            path.pathVerts[i] = new Vector2(
                EditorGUILayout.FloatField(path.pathVerts[i].x),
                EditorGUILayout.FloatField(path.pathVerts[i].y));
            EditorGUILayout.EndHorizontal();
        }

        // button for updating the origin of the object
        if (GUILayout.Button("Center Position"))
        {
            path.ReCenter();
        }

        // update dependants when it changes
        if (GUI.changed)
        {
            Ferr2DT_PathTerrain terrain = path.GetComponent <Ferr2DT_PathTerrain>();
            if (!path.closed && terrain != null && (terrain.fill == Ferr2DT_FillMode.Closed || terrain.fill == Ferr2DT_FillMode.InvertedClosed || terrain.fill == Ferr2DT_FillMode.FillOnlyClosed))
            {
                path.closed = true;
            }
            path.UpdateDependants();
            EditorUtility.SetDirty(target);
        }
    }
        /**
         * Called when a property on a Ferr2D component is changed by another user. Rebuilds the Ferr2D mesh.
         *
         * @param   SerializedProperty property that changed.
         */
        private static void OnPropertyChange(SerializedProperty property)
        {
            Component component = property.serializedObject.targetObject as Component;

            if (component == null)
            {
                return;
            }

            Ferr2DT_PathTerrain terrain = component.GetComponent <Ferr2DT_PathTerrain>();

            if (terrain == null || terrain.Path == null)
            {
                return;
            }

            Ferr2D_Path path = terrain.Path;

            if (!m_rebuiltPaths.Add(path))
            {
                // We've already rebuilt the mesh this frame.
                return;
            }

            sfFerr2DAdaptor adaptor = path.GetComponent <sfFerr2DAdaptor>();

            if (adaptor != null && !adaptor.HasControlledMesh)
            {
                // The mesh on this object was not generated by the Ferr2D components on this object. If we
                // rebuild it will replace the existing mesh which we do not want.
                return;
            }

            MeshFilter filter = path.GetComponent <MeshFilter>();

            if (filter != null && filter.sharedMesh != null)
            {
                // Ensure the mesh name is what Ferr2D expects so Ferr2D will update the existing mesh instead of
                // creating a new one.
                filter.sharedMesh.name = terrain.GetMeshName();
            }

            // Rebuild the mesh
            path.UpdateDependants(true);

            // Rebuild the collider in play mode
            if (EditorApplication.isPlaying)
            {
                path.UpdateColliders();
            }
        }
Exemplo n.º 4
0
 private void    UpdateDependentsSmart(Ferr2D_Path aPath, bool aForce, bool aFullUpdate)
 {
     if (aForce || Ferr2DT_Menu.UpdateTerrainSkipFrames == 0 || updateCount % Ferr2DT_Menu.UpdateTerrainSkipFrames == 0)
     {
         aPath.UpdateDependants(aFullUpdate);
         if (Application.isPlaying)
         {
             aPath.UpdateColliders();
         }
         if (OnChanged != null)
         {
             OnChanged();
         }
     }
     updateCount += 1;
 }
Exemplo n.º 5
0
	private void    UpdateDependentsSmart(Ferr2D_Path aPath, bool aForce, bool aFullUpdate) {
		if (aForce || Ferr2DT_Menu.UpdateTerrainSkipFrames == 0 || updateCount % Ferr2DT_Menu.UpdateTerrainSkipFrames == 0) {
			aPath.UpdateDependants(aFullUpdate);
			if (Application.isPlaying) aPath.UpdateColliders();
			if (OnChanged != null) OnChanged();
		}
		updateCount += 1;
	}
Exemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        Ferr2D_Path path       = (Ferr2D_Path)target;
        bool        updateMesh = false;

        // if this was an undo, refresh stuff too
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":

                path.UpdateDependants(true);
                if (OnChanged != null)
                {
                    OnChanged();
                }
                return;
            }
        }

        EditorGUILayout.PropertyField(closed);
        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(pathVerts, true);
        if (EditorGUI.EndChangeCheck() && PrefabUtility.GetPrefabParent(target) != null)
        {
            NudgeArray(pathVerts);
        }

        // button for updating the origin of the object
        if (GUILayout.Button("Center Position"))
        {
            Undo.RecordObject(target, "Modified Path");
            path.ReCenter();
            updateMesh = true;
        }

        Ferr2DT_PathTerrain terrain = path.GetComponent <Ferr2DT_PathTerrain>();

        if (!path.closed && (terrain.fill == Ferr2DT_FillMode.Closed || terrain.fill == Ferr2DT_FillMode.InvertedClosed || terrain.fill == Ferr2DT_FillMode.FillOnlyClosed))
        {
            Undo.RecordObject(target, "Modified Path");
            path.closed = true;
            updateMesh  = true;
        }
        if (path.closed && (terrain.fill == Ferr2DT_FillMode.FillOnlySkirt || terrain.fill == Ferr2DT_FillMode.Skirt))
        {
            Undo.RecordObject(target, "Modified Path");
            path.closed = false;
            updateMesh  = true;
        }

        // update dependants when it changes
        if (updateMesh || serializedObject.ApplyModifiedProperties())
        {
            if (OnChanged != null)
            {
                OnChanged();
            }
            path.UpdateDependants(true);
            EditorUtility.SetDirty(target);
        }
    }
Exemplo n.º 7
0
    private void OnSceneGUI()
    {
        Ferr2D_Path path      = (Ferr2D_Path)target;
        GUIStyle    iconStyle = new GUIStyle();

        iconStyle.alignment = TextAnchor.MiddleCenter;
        snap = new Vector3(EditorPrefs.GetFloat("MoveSnapX", 1), EditorPrefs.GetFloat("MoveSnapY", 1), EditorPrefs.GetFloat("MoveSnapZ", 1));

        // setup undoing things
        Undo.RecordObject(target, "Modified Path");

        // draw the path line
        if (Event.current.type == EventType.Repaint)
        {
            DoPath(path);
        }

        // Check for drag-selecting multiple points
        DragSelect(path);

        // do adding verts in when the shift key is down!
        if (Event.current.shift && !Event.current.control)
        {
            DoShiftAdd(path, iconStyle);
        }

        // draw and interact with all the path handles
        DoHandles(path, iconStyle);

        // if this was an undo, refresh stuff too
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
                // Only rebuild this from an undo if the inspector is not visible.
                UnityEngine.Object[] objs = Resources.FindObjectsOfTypeAll(Type.GetType("UnityEditor.InspectorWindow, UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", true));
                if (objs == null || objs.Length == 0)
                {
                    path.UpdateDependants(true);
                    if (OnChanged != null)
                    {
                        OnChanged();
                    }
                }
                break;
            }
        }

        // update everything that relies on this path, if the GUI changed
        if (GUI.changed)
        {
            if (PrefabUtility.GetPrefabParent(target) != null)
            {
                NudgeArray(pathVerts);
                serializedObject.ApplyModifiedProperties();
            }

            UpdateDependentsSmart(path, false, false);
            EditorUtility.SetDirty(target);
            prevChanged = true;
        }
        else if (Event.current.type == EventType.Used)
        {
            if (prevChanged == true)
            {
                UpdateDependentsSmart(path, false, true);
            }
            prevChanged = false;
        }
    }
    public override void OnInspectorGUI()
    {
        Undo.RecordObject(target, "Modified Path");

        Ferr2D_Path path = (Ferr2D_Path)target;

        // if this was an undo, refresh stuff too
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":

                path.UpdateDependants(true);
                if (OnChanged != null)
                {
                    OnChanged();
                }
                return;
            }
        }

        path.closed = EditorGUILayout.Toggle("Closed", path.closed);
        if (path)
        {
            // display the path verts list info
            showVerts = EditorGUILayout.Foldout(showVerts, "Path Vertices");
        }
        EditorGUI.indentLevel = 2;
        if (showVerts)
        {
            int size = EditorGUILayout.IntField("Count: ", path.pathVerts.Count);
            while (path.pathVerts.Count > size)
            {
                path.pathVerts.RemoveAt(path.pathVerts.Count - 1);
            }
            while (path.pathVerts.Count < size)
            {
                path.pathVerts.Add(new Vector2(0, 0));
            }
        }
        // draw all the verts! Long list~
        for (int i = 0; showVerts && i < path.pathVerts.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("#" + i, GUILayout.Width(60));
            path.pathVerts[i] = new Vector2(
                EditorGUILayout.FloatField(path.pathVerts[i].x),
                EditorGUILayout.FloatField(path.pathVerts[i].y));
            EditorGUILayout.EndHorizontal();
        }

        // button for updating the origin of the object
        if (GUILayout.Button("Center Position"))
        {
            path.ReCenter();
        }

        bool updateClosed           = false;
        Ferr2DT_PathTerrain terrain = path.GetComponent <Ferr2DT_PathTerrain>();

        if (!path.closed && terrain != null && (terrain.fill == Ferr2DT_FillMode.Closed || terrain.fill == Ferr2DT_FillMode.InvertedClosed || terrain.fill == Ferr2DT_FillMode.FillOnlyClosed))
        {
            path.closed  = true;
            updateClosed = true;
        }
        if (terrain != null && path.closed && (terrain.fill == Ferr2DT_FillMode.FillOnlySkirt || terrain.fill == Ferr2DT_FillMode.Skirt))
        {
            path.closed  = false;
            updateClosed = true;
        }

        // update dependants when it changes
        if (GUI.changed || updateClosed)
        {
            path.UpdateDependants(false);
            EditorUtility.SetDirty(target);
        }
    }
    void OnGUI()
    {
        radius      = EditorGUILayout.FloatField("Radius", radius);
        placeAround = (Transform)EditorGUILayout.ObjectField(placeAround, typeof(Transform), true);

        GUILayout.Label("Parent Transform for Points", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();
        doTransform = EditorGUILayout.Toggle(doTransform, GUILayout.Width(14f));
        parentItem  = (Transform)EditorGUILayout.ObjectField(parentItem, typeof(Transform), true);
        EditorGUILayout.EndHorizontal();

        GUILayout.Label("EdgeCollider GameObject", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();
        doEdgeCollider = EditorGUILayout.Toggle(doEdgeCollider, GUILayout.Width(14f));
        edgeCollider   = (EdgeCollider2D)EditorGUILayout.ObjectField(edgeCollider, typeof(EdgeCollider2D), true);
        EditorGUILayout.EndHorizontal();

        GUILayout.Label("Ferr2D terrain points", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();
        doFerrTerrain = EditorGUILayout.Toggle(doFerrTerrain, GUILayout.Width(14f));
        path          = (Ferr2D_Path)EditorGUILayout.ObjectField(path, typeof(Ferr2D_Path), true);
        EditorGUILayout.EndHorizontal();


        if (GUI.Button(new Rect(3, 170, position.width - 6, 20), "Make a Circle"))
        {
            if (doTransform && parentItem)
            {
                Transform[] transforms = parentItem.GetComponentsInChildren <Transform>();
                Vector2[]   tempPoints = new Vector2[transforms.Length];

                int i = 0;
                foreach (Transform t in transforms)
                {
                    tempPoints[i].x = t.position.x;
                    tempPoints[i].y = t.position.y;

                    i++;
                }

                if (placeAround)
                {
                    PlacePointsInACircle(ref tempPoints, radius, placeAround.position);
                }
                else
                {
                    PlacePointsInACircle(ref tempPoints, radius, Vector2.zero);
                }

                i = 0;
                foreach (Vector2 p in tempPoints)
                {
                    transforms[i].position = new Vector3(p.x, p.y, 0f);
                    i++;
                }
            }
            if (doEdgeCollider && edgeCollider)
            {
                Vector2[] tempPoints = edgeCollider.points;

                if (placeAround)
                {
                    PlacePointsInACircle(ref tempPoints, radius, placeAround.position);
                }
                else
                {
                    PlacePointsInACircle(ref tempPoints, radius, Vector2.zero);
                }

                edgeCollider.points = tempPoints;
            }
            if (doFerrTerrain && path)
            {
                Vector2[] tempPoints = path.GetVertsRaw().ToArray();

                if (placeAround)
                {
                    PlacePointsInACircle(ref tempPoints, radius, placeAround.position, false);
                }
                else
                {
                    PlacePointsInACircle(ref tempPoints, radius, Vector2.zero, false);
                }

                path.pathVerts = new List <Vector2>(tempPoints);

                path.UpdateColliders();
                path.UpdateDependants(true);
            }
        }
    }
Exemplo n.º 10
0
    public override void OnInspectorGUI()
    {
        EditorTools.TitleField("地板編輯工具");
        Undo.RecordObject(target, "Modified Path");

        Ferr2D_Path path = (Ferr2D_Path)target;

        // if this was an undo, refresh stuff too
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":

                path.UpdateDependants(true);
                if (OnChanged != null)
                {
                    OnChanged();
                }
                return;
            }
        }

        path.closed = EditorGUILayout.Toggle("封閉地面", path.closed);
        if (path)
        {
            // display the path verts list info
            showVerts = EditorGUILayout.Foldout(showVerts, "頂點座標");
        }
        EditorGUI.indentLevel = 2;
        if (showVerts)
        {
            int size = EditorGUILayout.IntField("數量: ", path.pathVerts.Count);
            while (path.pathVerts.Count > size)
            {
                path.pathVerts.RemoveAt(path.pathVerts.Count - 1);
            }
            while (path.pathVerts.Count < size)
            {
                path.pathVerts.Add(new Vector2(0, 0));
            }
        }
        // draw all the verts! Long list~
        for (int i = 0; showVerts && i < path.pathVerts.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("#" + i, GUILayout.Width(60));
            path.pathVerts[i] = new Vector2(
                EditorGUILayout.FloatField(path.pathVerts[i].x),
                EditorGUILayout.FloatField(path.pathVerts[i].y));
            EditorGUILayout.EndHorizontal();
        }

        // button for updating the origin of the object

        if (GUILayout.Button("座標重置"))
        {
            path.ReCenter();
        }

        bool updateClosed           = false;
        Ferr2DT_PathTerrain terrain = path.GetComponent <Ferr2DT_PathTerrain>();

        if (!path.closed && terrain != null && (terrain.fill == Ferr2DT_FillMode.Closed || terrain.fill == Ferr2DT_FillMode.InvertedClosed || terrain.fill == Ferr2DT_FillMode.FillOnlyClosed))
        {
            path.closed  = true;
            updateClosed = true;
        }
        if (terrain != null && path.closed && (terrain.fill == Ferr2DT_FillMode.FillOnlySkirt || terrain.fill == Ferr2DT_FillMode.Skirt))
        {
            path.closed  = false;
            updateClosed = true;
        }

        // update dependants when it changes
        if (GUI.changed || updateClosed)
        {
            path.UpdateDependants(false);
            EditorUtility.SetDirty(target);
        }

        sizeX = EditorTools.IntField(sizeX, "寬");
        sizeY = EditorTools.IntField(sizeY, "長");

        if (GUILayout.Button("地板格式化"))
        {
            path.pathVerts = new List <Vector2>();
            path.pathVerts.Add(new Vector2(sizeX, sizeY) * 0.5F);
            path.pathVerts.Add(new Vector2(sizeX, -sizeY) * 0.5F);
            path.pathVerts.Add(new Vector2(-sizeX, -sizeY) * 0.5F);
            path.pathVerts.Add(new Vector2(-sizeX, sizeY) * 0.5F);
            UpdateDependentsSmart(path, false, false);
            EditorUtility.SetDirty(target);
            prevChanged = true;

            BoxCollider2D box2D = path.GetComponent <BoxCollider2D>();
            if (box2D)
            {
                path.GetComponent <BoxCollider2D>().size = new Vector2(sizeX, sizeY);
                EditorUtility.SetDirty(path.GetComponent <BoxCollider2D>());
            }
        }

        if (GUILayout.Button("進階地板設定"))
        {
            GroundBase groundBase = path.GetComponent <GroundBase>();
            if (!groundBase)
            {
                path.gameObject.AddComponent <GroundBase>();
            }
        }

        EditorTools.Mig();
    }
Exemplo n.º 11
0
 private void UpdateDependentsSmart(Ferr2D_Path aPath, bool aForce) {
     if (aForce || Ferr_Menu.UpdateTerrainSkipFrames == 0 || updateCount % Ferr_Menu.UpdateTerrainSkipFrames == 0) {
         aPath.UpdateDependants();
     }
     updateCount += 1;
 }