示例#1
0
    private static void NewMenuOption()
    {
        GameObject     tree  = new GameObject("tree");
        MtreeComponent mtree = tree.AddComponent <MtreeComponent>();

        mtree.GenerateTree();
        Selection.activeGameObject = tree;
    }
示例#2
0
 private void OnEnable()
 {
     tree = (MtreeComponent)target;
     tree.UpdateTreeFunctions();
     if (tree.tree == null)
     {
         UpdateTree();
     }
     rectHeightMultiplier    = TreeFunction.height + TreeFunction.margin;
     Undo.undoRedoPerformed += UndoCallback;
 }
示例#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;
        }
    }
示例#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;
        }
示例#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;
        }