Ejemplo n.º 1
0
    private static void NewMenuOption()
    {
        GameObject     tree  = new GameObject("tree");
        MtreeComponent mtree = tree.AddComponent <MtreeComponent>();

        mtree.GenerateTree();
        Selection.activeGameObject = tree;
    }
Ejemplo n.º 2
0
 private void OnEnable()
 {
     tree = (MtreeComponent)target;
     tree.UpdateTreeFunctions();
     if (tree.tree == null)
     {
         UpdateTree();
     }
     rectHeightMultiplier    = TreeFunction.height + TreeFunction.margin;
     Undo.undoRedoPerformed += UndoCallback;
 }
Ejemplo n.º 3
0
    private static void CreateNewMtree()
    {
        GameObject     tree  = new GameObject("New Mtree");
        MtreeComponent mtree = tree.AddComponent <MtreeComponent>();

        mtree.GenerateTree();
        Selection.activeGameObject = tree;
        if (SceneView.lastActiveSceneView != null)
        {
            tree.gameObject.transform.position = SceneView.lastActiveSceneView.pivot;
        }
    }
Ejemplo n.º 4
0
        public static void OnCreatePrefab(GameObject instance)
        {
            if (instance.GetComponent <MtreeComponent>() == null)
            {
                return;
            }

            #if UNITY_2018_3_OR_NEWER
            string prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(instance);
            #else
            string prefabPath = AssetDatabase.GetAssetPath(PrefabUtility.GetPrefabParent(instance));
            #endif
            MtreeComponent[] trees      = (MtreeComponent[])GameObject.FindObjectsOfType(typeof(MtreeComponent));
            MtreeComponent   originTree = null;
            foreach (MtreeComponent tree in trees)
            {
                #if UNITY_2018_3_OR_NEWER
                bool   isInstance       = PrefabUtility.GetPrefabInstanceStatus(tree) == PrefabInstanceStatus.Connected;
                string parentPrefabPath = AssetDatabase.GetAssetPath(PrefabUtility.GetCorrespondingObjectFromSource(tree));
                #else
                bool   isInstance       = PrefabUtility.GetPrefabType(tree) == PrefabType.PrefabInstance;
                string parentPrefabPath = AssetDatabase.GetAssetPath(PrefabUtility.GetPrefabParent(tree));
                #endif
                if (isInstance && parentPrefabPath == prefabPath)
                {
                    #if UNITY_2018_3_OR_NEWER
                    PrefabUtility.UnpackPrefabInstance(tree.gameObject, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction);
                    #else
                    PrefabUtility.DisconnectPrefabInstance(tree);
                    #endif
                    originTree = tree;
                }
            }


            #if UNITY_2018_3_OR_NEWER // Unity 2017 crashes when deleting prefab at this stage. This part is therefore also done in the MtreeComponent editor
            AssetDatabase.DeleteAsset(prefabPath);
            AssetDatabase.Refresh();
            #endif

            if (originTree == null)
            {
                return;
            }

            string       templatePath = AssetDatabase.GenerateUniqueAssetPath(Path.GetDirectoryName(prefabPath) + "/" + originTree.name + ".asset");
            TreeTemplate template     = TreeTemplate.CreateFromFunctions(originTree.treeFunctionsAssets, templatePath);
            originTree.template = template;
        }
Ejemplo n.º 5
0
        private void OnEnable()
        {
            tree = (MtreeComponent)target;
#if UNITY_2018_3_OR_NEWER
            if (PrefabUtility.GetPrefabInstanceHandle(target) != null) // Prefabs with MtreeComponents should not be made as it tempers with the TreeFunctionAsset objects. Thus prefabs are deleted
            {
                DeletePefab();
                return;
            }
#else
            if (PrefabUtility.GetPrefabObject(target) != null) // Prefabs with MtreeComponents should not be made as it tempers with the TreeFunctionAsset objects. Thus prefabs are deleted
            {
                DeletePefab();
                return;
            }
#endif
            if (tree.tree == null && tree.MtreeVersion == Mtree.MtreeVariables.MtreeVersion)
            {
                UpdateTree();
            }
            rectHeightMultiplier    = TreeFunction.height + TreeFunction.margin;
            Undo.undoRedoPerformed += tree.UndoCallBack;
        }