/**
         * Called before syncing a game object for the first time. Adds our adaptor component to Ferr2D objects to sync
         * some additional data.
         *
         * @param   GameObject gameObject a spawn request will be sent for.
         * @return  bool true - we always want to sync the object.
         */
        private static bool BeforeFirstSync(GameObject gameObject)
        {
            Ferr2D_Path path = gameObject.GetComponent <Ferr2D_Path>();

            if (path != null)
            {
                // This is a Ferr2D object. Add our adaptor component if there isn't one already.
                sfFerr2DAdaptor adaptor = gameObject.GetComponent <sfFerr2DAdaptor>();
                if (adaptor == null)
                {
                    adaptor = gameObject.AddComponent <sfFerr2DAdaptor>();
                }
                if (adaptor.HasControlledMesh)
                {
                    MeshFilter filter = gameObject.GetComponent <MeshFilter>();
                    if (filter != null && filter.sharedMesh != null)
                    {
                        // The game object has a mesh whose data is controlled by Ferr2D. Tell Scene Fusion not to
                        // upload the mesh data since Ferr2D will be generating it.
                        sfObjectUtility.DontUploadSceneAsset(filter.sharedMesh);
                    }
                }
            }
            return(true);
        }
Beispiel #2
0
        /**
         * Called to draw the scene GUI.
         */
        private void OnSceneGUI()
        {
            // Ferr2D can change the mesh from OnSceneGUI so we need to check for a new mesh here.
            sfFerr2DAdaptor adaptor = target as sfFerr2DAdaptor;

            if (adaptor != null)
            {
                adaptor.CheckMesh();
            }
        }
Beispiel #3
0
        /**
         * Called to draw the inspector GUI.
         */
        public override void OnInspectorGUI()
        {
            EditorGUILayout.HelpBox("This component syncs additional data needed to make Scene Fusion and Ferr2D work well together. " +
                                    "Do not remove it while using Scene Fusion.", MessageType.Info);

            // While the object is selected, check if its mesh is controlled by Ferr2D.
            sfFerr2DAdaptor adaptor = target as sfFerr2DAdaptor;

            if (adaptor != null)
            {
                adaptor.CheckMesh();
            }
        }
        /**
         * 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();
            }
        }