/**
         * 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.º 2
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.º 3
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;
	}
    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);
            }
        }
    }