コード例 #1
0
        internal static void SetupIDs(NetworkIdentity identity)
        {
            var         wrapper = new IdentityWrapper(identity);
            PrefabStage stage;

            if (PrefabUtility.IsPartOfPrefabAsset(identity.gameObject))
            {
                wrapper.ClearSceneId();
                AssignAssetID(identity);
            }
            // Unity calls OnValidate for prefab and other scene objects based on that prefab
            //
            // are we modifying THIS prefab, or just a scene object based on the prefab?
            //   * GetCurrentPrefabStage = 'are we editing ANY prefab?'
            //   * GetPrefabStage(go) = 'are we editing THIS prefab?'
            else if ((stage = PrefabStageUtility.GetCurrentPrefabStage()) != null)
            {
                // nested if, we want to do nothing if we are not the prefab being edited
                if (PrefabStageUtility.GetPrefabStage(identity.gameObject) != null)
                {
                    wrapper.ClearSceneId();
                    AssignAssetID(identity, GetStagePath(stage));
                }
            }
            else if (SceneObjectWithPrefabParent(identity, out GameObject parent))
            {
                AssignSceneID(identity);
                AssignAssetID(identity, parent);
            }
            else
            {
                AssignSceneID(identity);
                wrapper.PrefabHash = 0;
            }
        }
コード例 #2
0
        static string GetAndEnsureTargetPath(NavMeshSurface surface)
        {
            // Create directory for the asset if it does not exist yet.
            var activeScenePath = surface.gameObject.scene.path;

            var targetPath = "Assets";

            if (!string.IsNullOrEmpty(activeScenePath))
            {
                targetPath = Path.Combine(Path.GetDirectoryName(activeScenePath), Path.GetFileNameWithoutExtension(activeScenePath));
            }
            else
            {
                var prefabStage    = PrefabStageUtility.GetPrefabStage(surface.gameObject);
                var isPartOfPrefab = prefabStage != null && prefabStage.IsPartOfPrefabContents(surface.gameObject);
                if (isPartOfPrefab && !string.IsNullOrEmpty(prefabStage.prefabAssetPath))
                {
                    var prefabDirectoryName = Path.GetDirectoryName(prefabStage.prefabAssetPath);
                    if (!string.IsNullOrEmpty(prefabDirectoryName))
                    {
                        targetPath = prefabDirectoryName;
                    }
                }
            }
            if (!Directory.Exists(targetPath))
            {
                Directory.CreateDirectory(targetPath);
            }
            return(targetPath);
        }
コード例 #3
0
    public void Save()
    {
        var mainStage    = StageUtility.GetMainStageHandle();
        var currentStage = StageUtility.GetStageHandle(gameObject);

        if (mainStage == currentStage)
        {
            if (PrefabUtility.IsPartOfPrefabInstance(gameObject))
            {
                // Prefab instance
                var scene = SceneManager.GetActiveScene();
                UpdateChanges(gameObject, AssetDatabase.LoadAssetAtPath(scene.path, typeof(SceneAsset)));
            }
            else
            {
                // Normal object in scene
                var scene = SceneManager.GetActiveScene();
                UpdateChanges(gameObject, AssetDatabase.LoadAssetAtPath(scene.path, typeof(SceneAsset)));
            }
        }
        else
        {
            var prefabStage = PrefabStageUtility.GetPrefabStage(gameObject);
            if (prefabStage != null)
            {
                UpdateChanges(AssetDatabase.LoadAssetAtPath(prefabStage.prefabAssetPath, typeof(GameObject)));
            }
        }
    }
コード例 #4
0
        protected override void OnInspector()
        {
            TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);

            if (P3dMaterial.CachedMaterials.Contains(tgt) == false && P3dHelper.IsAsset(tgt) == true)
            {
                P3dMaterial.CachedMaterials.Add(tgt);
            }

            Draw("category");
            Draw("icon");
            DrawTextures();

            Separator();

            var prefabIsOpen = PrefabStageUtility.GetPrefabStage(tgt.gameObject) != null;

            if (prefabIsOpen == false)
            {
                Info("Open this material prefab to build the materials or icons.");
            }

            BeginDisabled(prefabIsOpen == false);
            EditorGUILayout.LabelField("Material Builder", EditorStyles.boldLabel);

            DrawMaterialBuilder(tgt);

            Separator();

            EditorGUILayout.LabelField("Icon Builder", EditorStyles.boldLabel);

            DrawIconBuilder(tgt);
            EndDisabled();
        }
コード例 #5
0
    private bool CheckIfIsPrefab()
    {
        PrefabStage prefabStage = PrefabStageUtility.GetPrefabStage(gameObject);

        //Debug.Log("IsPrefabSource: " + gameObject + " : " + prefabStage+", "+ (prefabStage != null));
        return(IsPrefab = (prefabStage != null));
    }
コード例 #6
0
		/// <summary>
		/// Returns true if the given object is being edited in prefab mode.
		/// </summary>
		/// <param name="obj">Object to check</param>
		/// <returns>True if object is in prefab mode</returns>
		public static bool IsEditingInPrefabMode(GameObject obj)
		{
#if UNITY_EDITOR
			if (EditorUtility.IsPersistent(obj))
			{
				// Stored on disk (some sort of prefab)
				return true;
			}
			else
			{
#if UNITY_2018_3_OR_NEWER
				// If not persistent, check if in prefab stage
				if (StageUtility.GetMainStageHandle() != StageUtility.GetStageHandle(obj))
				{
					var stage = PrefabStageUtility.GetPrefabStage(obj);
					if (stage != null)
					{
						return true;
					}
				}
#endif
			}
#endif
			return false;
		}
コード例 #7
0
        NavMeshData GetNavMeshAssetToDelete(NavMeshSurface navSurface)
        {
#if UNITY_2018_3_OR_NEWER
            if (PrefabUtility.IsPartOfPrefabInstance(navSurface) && !PrefabUtility.IsPartOfModelPrefab(navSurface))
#else
            var prefabType = PrefabUtility.GetPrefabType(navSurface);
            if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
#endif
            {
                // Don't allow deleting the asset belonging to the prefab parent
#if UNITY_2018_2_OR_NEWER
                var parentSurface = PrefabUtility.GetCorrespondingObjectFromSource(navSurface) as NavMeshSurface;
#else
                var parentSurface = PrefabUtility.GetPrefabParent(navSurface) as NavMeshSurface;
#endif
                if (parentSurface && navSurface.navMeshData == parentSurface.navMeshData)
                {
                    return(null);
                }
            }

#if UNITY_2018_3_OR_NEWER
            // Do not delete the NavMeshData asset referenced from a prefab until the prefab is saved
            var prefabStage    = PrefabStageUtility.GetPrefabStage(navSurface.gameObject);
            var isPartOfPrefab = prefabStage != null && prefabStage.IsPartOfPrefabContents(navSurface.gameObject);
            if (isPartOfPrefab && IsCurrentPrefabNavMeshDataStored(navSurface))
            {
                return(null);
            }
#endif

            return(navSurface.navMeshData);
        }
コード例 #8
0
        private static bool ContainsDuplicateGlobalLight(int sortingLayerIndex, int blendStyleIndex)
        {
            var globalLightCount = 0;

            // This should be rewritten to search only global lights
            foreach (var light in lights)
            {
                if (light.lightType == Light2D.LightType.Global &&
                    light.blendStyleIndex == blendStyleIndex &&
                    light.IsLitLayer(sortingLayerIndex))
                {
#if UNITY_EDITOR
                    // If we found the first global light in our prefab stage
                    if (PrefabStageUtility.GetPrefabStage(light.gameObject) == PrefabStageUtility.GetCurrentPrefabStage())
#endif
                    {
                        if (globalLightCount > 0)
                        {
                            return(true);
                        }

                        globalLightCount++;
                    }
                }
            }

            return(false);
        }
コード例 #9
0
ファイル: P3dMaterial.cs プロジェクト: Nolgoroe/Shoe-Project
        protected override void OnInspector()
        {
            if (P3dMaterial.CachedMaterials.Contains(Target) == false && P3dHelper.IsAsset(Target) == true)
            {
                P3dMaterial.CachedMaterials.Add(Target);
            }

            Draw("category");
            Draw("icon");
            DrawTextures();

            EditorGUILayout.Separator();

            var prefabIsOpen = PrefabStageUtility.GetPrefabStage(Target.gameObject) != null;

            if (prefabIsOpen == false)
            {
                EditorGUILayout.HelpBox("Open this material prefab to build the materials or icons.", MessageType.Info);
            }

            EditorGUI.BeginDisabledGroup(prefabIsOpen == false);
            EditorGUILayout.LabelField("Material Builder", EditorStyles.boldLabel);

            DrawMaterialBuilder();

            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("Icon Builder", EditorStyles.boldLabel);

            DrawIconBuilder();
            EditorGUI.EndDisabledGroup();
        }
コード例 #10
0
        public static string TryGetObjectAssetPath(Object target)
        {
            var assetPath = AssetDatabase.GetAssetOrScenePath(target);

#if UNITY_2018_3_OR_NEWER
            if (string.IsNullOrEmpty(assetPath))
            {
                var component  = target as Component;
                var gameObject = target as GameObject;

                if (component != null)
                {
                    gameObject = component.gameObject;
                }

                if (gameObject == null)
                {
                    return(null);
                }

                var prefabStage = PrefabStageUtility.GetPrefabStage(gameObject);
                if (prefabStage != null)
                {
#if UNITY_2020_1_OR_NEWER
                    assetPath = prefabStage.assetPath;
#else
                    assetPath = prefabStage.prefabAssetPath;
#endif
                }
            }
#endif
            return(assetPath);
        }
コード例 #11
0
 public Item(Object obj)
 {
     if (obj is GameObject go)
     {
         if (!go.scene.IsValid())
         {
             _object    = obj;
             _assetPath = AssetDatabase.GetAssetPath(obj);
             _type      = ItemType.Prefab;
         }
         else
         {
             PrefabStage stage = PrefabStageUtility.GetPrefabStage(go);
             if (stage != null && stage.prefabContentsRoot == go)
             {
                 _object    = stage.prefabContentsRoot;
                 _assetPath = stage.prefabAssetPath;
                 _type      = ItemType.Prefab;
             }
             else
             {
                 _object     = obj;
                 _assetPath  = go.scene.path;
                 _instanceID = go.GetInstanceID();
                 _type       = ItemType.HierachyObject;
             }
         }
     }
     else
     {
         _object    = obj;
         _assetPath = AssetDatabase.GetAssetPath(obj);
         _type      = ItemType.Asset;
     }
 }
コード例 #12
0
        public override void ProcessAsset(SearchJob job)
        {
#if UNITY_2018_3_OR_NEWER
            PrefabStage stage = PrefabStageUtility.GetPrefabStage(sceneObjects[0]);
            if (stage != null)
            {
                isInPrefabStage = true;
            }
#endif

            roots = sceneObjects.ToArray();

            job.OnAssetSearchBegin();
            foreach (GameObject root in roots)
            {
                job.searchGameObject(root);
            }

#if UNITY_2018_3_OR_NEWER
            if (assetIsDirty && isInPrefabStage)
            {
                EditorSceneManager.MarkSceneDirty(stage.scene);
            }
#endif
        }
コード例 #13
0
ファイル: SpawnerBrush.cs プロジェクト: Mapz/SuperSimon
        public override void Erase(GridLayout grid, GameObject brushTarget, Vector3Int pos)
        {
            if (brushTarget.layer == 31)
            {
                return;
            }

            //Tilemap layerTilemap = brushTarget.GetComponent<Tilemap>();
            UnitSpawner spawner = brushTarget.GetComponent <UnitSpawner>();

            if (spawner == null)
            {
                Debug.LogError("TileMap对象必须包含一个 生怪器 组件");
                return;
            }
            if (m_window)
            {
                m_window.Close();
            }

            for (int i = 0; i < spawner.spawns.Count; i++)
            {
                if (pos == spawner.spawns[i].position)
                {
                    spawner.spawns.Remove(spawner.spawns[i]);
                    //Set Prefab Dirty
                    var prefabStage = PrefabStageUtility.GetPrefabStage(spawner.gameObject);
                    if (prefabStage != null)
                    {
                        EditorSceneManager.MarkSceneDirty(prefabStage.scene);
                    }
                    return;
                }
            }
        }
コード例 #14
0
        public EObjectStage GetObjectStage()
        {
#if UNITY_EDITOR
            if (EditorUtility.IsPersistent(gameObject))
            {
                return(EObjectStage.PRESISTENCE_STAGE);
            }

            // If the GameObject is not persistent let's determine which stage we are in first because getting Prefab info depends on it
            var mainStage    = StageUtility.GetMainStageHandle();
            var currentStage = StageUtility.GetStageHandle(gameObject);
            if (currentStage == mainStage)
            {
                if (PrefabUtility.IsPartOfPrefabInstance(gameObject))
                {
                    var type = PrefabUtility.GetPrefabAssetType(gameObject);
                    var path = AssetDatabase.GetAssetPath(PrefabUtility.GetCorrespondingObjectFromSource(gameObject));
                    //Debug.Log(string.Format("GameObject is part of a Prefab Instance in the MainStage and is of type: {0}. It comes from the prefab asset: {1}", type, path));
                    return(EObjectStage.MAIN_STAGE);
                }
                else
                {
                    //Debug.Log("GameObject is a plain GameObject in the MainStage");
                    return(EObjectStage.MAIN_STAGE);
                }
            }
            else
            {
                var prefabStage = PrefabStageUtility.GetPrefabStage(gameObject);
                if (prefabStage != null)
                {
                    if (PrefabUtility.IsPartOfPrefabInstance(gameObject))
                    {
                        var type             = PrefabUtility.GetPrefabAssetType(gameObject);
                        var nestedPrefabPath = AssetDatabase.GetAssetPath(PrefabUtility.GetCorrespondingObjectFromSource(gameObject));
                        //Debug.Log(string.Format("GameObject is in a PrefabStage. The GameObject is part of a nested Prefab Instance and is of type: {0}. The opened Prefab asset is: {1} and the nested Prefab asset is: {2}", type, prefabStage.prefabAssetPath, nestedPrefabPath));
                        return(EObjectStage.PREFAB_STAGE);
                    }
                    else
                    {
                        var prefabAssetRoot = AssetDatabase.LoadAssetAtPath <GameObject>(prefabStage.prefabAssetPath);
                        var type            = PrefabUtility.GetPrefabAssetType(prefabAssetRoot);
                        //Debug.Log(string.Format("GameObject is in a PrefabStage. The opened Prefab is of type: {0}. The GameObject comes from the prefab asset: {1}", type, prefabStage.prefabAssetPath));
                        return(EObjectStage.PREFAB_STAGE);
                    }
                }
                else if (EditorSceneManager.IsPreviewSceneObject(gameObject))
                {
                    //Debug.Log("GameObject is not in the MainStage, nor in a PrefabStage. But it is in a PreviewScene so could be used for Preview rendering or other utilities.");
                    return(EObjectStage.OTHER_STAGE);
                }
                else
                {
                    LogConsoleError("Unknown GameObject Info");
                }
            }
#endif
            return(EObjectStage.OTHER_STAGE);
        }
コード例 #15
0
 public static bool IsPrefabAssetOrOpenInPrefabStage(this GameObject gameObject)
 {
                 #if UNITY_2018_3_OR_NEWER
     return(PrefabUtility.IsPartOfPrefabAsset(gameObject) || PrefabStageUtility.GetPrefabStage(gameObject) != null);
                 #else
     return(PrefabUtility.GetPrefabType(gameObject) == PrefabType.Prefab);
                 #endif
 }
コード例 #16
0
 public static bool IsOpenInPrefabStage(this GameObject gameObject)
 {
                 #if UNITY_2018_3_OR_NEWER
     return(PrefabStageUtility.GetPrefabStage(gameObject) != null);
                 #else
     return(false);
                 #endif
 }
コード例 #17
0
        public static bool CanInitialize(this Agent agent)
        {
#if UNITY_EDITOR
            return(PrefabStageUtility.GetPrefabStage(agent.gameObject) == null);
#else
            return(true);
#endif
        }
コード例 #18
0
ファイル: MeshTweenEditor.cs プロジェクト: ismslv/Unity_Tween
        void SavePrefab()
        {
            var prefabStage = PrefabStageUtility.GetPrefabStage(meshTween.gameObject);

            if (prefabStage != null)
            {
                EditorSceneManager.MarkSceneDirty(prefabStage.scene);
            }
        }
コード例 #19
0
        public static string GetPrefabAssetPath(GameObject go)
        {
            string assetPath   = "";
            var    prefabStage = PrefabStageUtility.GetPrefabStage(go);

            if (prefabStage != null)
#if UNITY_2020_1_OR_NEWER
            { assetPath = prefabStage.assetPath; }
#else
            { assetPath = prefabStage.prefabAssetPath; }
コード例 #20
0
    void OnDestroy()
    {
        //Set Prefab Dirty
        var prefabStage = PrefabStageUtility.GetPrefabStage(m_unitSpawner.gameObject);

        if (prefabStage != null)
        {
            EditorSceneManager.MarkSceneDirty(prefabStage.scene);
        }
    }
コード例 #21
0
    private static Dictionary <string, string> ChangeCSharpPrefab(FieldInfo[] infos, object obj)
    {
        if (infos == null)
        {
            return(null);
        }
        Dictionary <string, string> nameDic = new Dictionary <string, string>();

        foreach (var item in infos)
        {
            var        val = item.GetValue(obj);
            GameObject go  = null;
            if (val is Component)
            {
                var com = val as Component;
                go = com.gameObject;
            }
            else if (val is MonoBehaviour)
            {
                var mono = val as MonoBehaviour;
                go = mono.gameObject;
            }
            else if (val is GameObject)
            {
                go = val as GameObject;
            }
            if (go != null)
            {
                var prefabStage = PrefabStageUtility.GetPrefabStage(go);
                if (prefabStage != null)
                {
                    if (ScriptsHelper.IsIgnored(go))
                    {
                        continue;
                    }
                    var type = item.FieldType;
                    foreach (var t in Const.m_ComponentDict)
                    {
                        if (t.Value == type)
                        {
                            var    data = ScriptsHelper.ParseName(go);
                            string tag  = t.Key;
                            data.tags.Add(tag);
                            Selection.activeGameObject = go;
                            HierarchyEditor.AddTag(tag);
                            nameDic[item.Name] = ScriptsHelper.GetFieldName(data.name, tag);
                            break;
                        }
                    }
                }
            }
        }
        return(nameDic);
    }
コード例 #22
0
        private void OnScene(SceneView sceneview)
        {
            var shouldDraw = true;

            //Checking if the current game object is inside of a prefab stage
            if (PrefabStageUtility.GetCurrentPrefabStage() != null)
            {
                shouldDraw = PrefabStageUtility.GetPrefabStage(gameObject) == PrefabStageUtility.GetCurrentPrefabStage();
            }

            if (shouldDraw)
            {
                if (_childNodes == null || _childNodes.Length == 0 || _previousTransforms == null || _previousTransforms.Length == 0)
                {
                    PopulateChildren();
                }

                Handles.color = BoneColor;

                foreach (var node in _childNodes)
                {
                    if (!node.transform.parent)
                    {
                        continue;
                    }
                    if (HideRoot && node == _preRootNode)
                    {
                        continue;
                    }

                    var start = node.transform.parent.position;
                    var end   = node.transform.position;

                    if (Handles.Button(node.transform.position, Quaternion.identity, BoneGizmosSize, BoneGizmosSize, Handles.SphereHandleCap))
                    {
                        Selection.activeGameObject = node.gameObject;
                    }

                    if (HideRoot && node.parent == _preRootNode)
                    {
                        continue;
                    }

                    if (node.transform.parent.childCount == 1)
                    {
                        Handles.DrawAAPolyLine(5f, start, end);
                    }
                    else
                    {
                        Handles.DrawDottedLine(start, end, 0.5f);
                    }
                }
            }
        }
コード例 #23
0
        public void PrefabModeSave(AutoGeneratePath info)
        {
            //判断是否是预设体模式
            var prefabStage = PrefabStageUtility.GetPrefabStage(info.gameObject);

            if (prefabStage != null)
            {
                //如果是那么设置场景脏  就会自动 保存
                EditorSceneManager.MarkSceneDirty(prefabStage.scene);
            }
        }
コード例 #24
0
        void parseIfSceneObject()
        {
            if (obj != null)
            {
                // Debug.Log("[ObjectID] guid: " + guid + " for  " + obj);
                if (guid == "")
                {
                    GameObject go = null;
                    if (obj is Component)
                    {
                        Component c = (Component)obj;
                        go = c.gameObject;
                    }
                    else
                    {
                        go = (GameObject)obj;
                    }
                    isSceneObject = go.scene.path.EndsWith(".unity");
                    if (isSceneObject)
                    {
                        guid = go.scene.path;
                    }
                    else
                    {
                        guid = AssetDatabase.AssetPathToGUID(go.scene.path);
#if UNITY_2018_3_OR_NEWER
                        PrefabStage stage = PrefabStageUtility.GetPrefabStage(go);
                        if (stage != null)
                        {
                            isPrefabStageObject = true;
                        }
#endif
                    }
                    localPath = PathData.ToPathData(obj);
                }
                else
                if (guid == SceneUtil.GuidPathForActiveScene())
                {
                    isSceneObject = true;
                    localPath     = PathData.ToPathData(obj);
                }
                else
                {
                    isSceneObject = false;
                    localPath     = null;
                }
            }
            else
            {
                isSceneObject = false;
                localPath     = null;
            }
        }
コード例 #25
0
    public static void SetLuaUIToInspector(GameObject go)
    {
        InspectorBase inspector = new LuaUIInspectorSetting();

        inspector.Execute(go);
        var prefabStage = PrefabStageUtility.GetPrefabStage(go);

        if (prefabStage != null)
        {
            EditorSceneManager.MarkSceneDirty(prefabStage.scene);
        }
    }
コード例 #26
0
        private static void CreateObject(List <Vector3> vertexes, List <Vector3> normals, List <Vector4> tangents, List <Color> colors, List <Vector2> uvs, List <int> triangles, Material material, Transform parent)
        {
            GameObject go = new GameObject();

            if (parent != null)
            {
                go.transform.SetParent(parent, false);
            }

            Undo.RegisterCreatedObjectUndo(go, "Create a new baked gameobject");

            ++objectNum;
            go.name = string.Format("Baked Mesh {0}", objectNum.ToString("D2"));

            MeshFilter   mf      = go.AddComponent <MeshFilter>();
            MeshRenderer mr      = go.AddComponent <MeshRenderer>();
            Mesh         newMesh = new Mesh();

            newMesh.SetVertices(vertexes);
            if (normals.Count != 0 && normalsResolving != Resolving.Remove)
            {
                newMesh.SetNormals(normals);
            }
            if (tangents.Count != 0 && tangentsResolving != Resolving.Remove)
            {
                newMesh.SetTangents(tangents);
            }
            if (colors.Count != 0 && colorResolving != Resolving.Remove)
            {
                newMesh.SetColors(colors);
            }
            if (uvs.Count != 0 || uvResolving != Resolving.Remove)
            {
                newMesh.SetUVs(0, uvs);
            }

            newMesh.SetTriangles(triangles, 0);
            mf.sharedMesh = newMesh;
            mr.material   = material;

            var prefabStage = PrefabStageUtility.GetPrefabStage(go);

            if (prefabStage != null && prefabStage.IsPartOfPrefabContents(go))
            {
                string assetName      = Path.GetFileNameWithoutExtension(prefabStage.prefabAssetPath);
                string assetDirectory = Path.GetDirectoryName(prefabStage.prefabAssetPath);

                string fileName = string.Format("{2}/{0}_{1}.asset", assetName, go.name, assetDirectory);
                AssetDatabase.CreateAsset(newMesh, fileName);
                AssetDatabase.SaveAssets();
            }
        }
コード例 #27
0
    private void PaintTileIfNeeded()
    {
        TacticsTerrainMesh terrain = (TacticsTerrainMesh)target;

        foreach (TerrainQuad quad in selectedQuads)
        {
            if (quad.normal.y > 0.0f)
            {
                int  originX = (int)primarySelection.pos.x - Mathf.FloorToInt(Mathf.RoundToInt(selectionSize.x) / 2.0f);
                int  originY = (int)primarySelection.pos.z - Mathf.FloorToInt(Mathf.RoundToInt(selectionSize.y) / 2.0f);
                Tile tile    = TileForSelection((int)(quad.pos.x - originX), (int)(quad.pos.z - originY));
                UpdateTile(quad, tile);
            }
            else
            {
                Tile tile;
                if (quad.normal.x != 0.0f)
                {
                    int originX = (int)primarySelection.pos.z - Mathf.FloorToInt(Mathf.RoundToInt(selectionSize.x) / 2.0f);
                    int originY = (int)primarySelection.pos.y - Mathf.FloorToInt(Mathf.RoundToInt(selectionSize.y) / 2.0f);
                    tile = TileForSelection((int)(quad.pos.z - originX), (int)(quad.pos.y - originY));
                }
                else
                {
                    int originX = (int)primarySelection.pos.x - Mathf.FloorToInt(Mathf.RoundToInt(selectionSize.x) / 2.0f);
                    int originY = (int)primarySelection.pos.y - Mathf.FloorToInt(Mathf.RoundToInt(selectionSize.y) / 2.0f);
                    tile = TileForSelection((int)(quad.pos.x - originX), (int)(quad.pos.y - originY));
                }
                if (wraparoundPaintMode)
                {
                    foreach (OrthoDir dir in Enum.GetValues(typeof(OrthoDir)))
                    {
                        UpdateTile(quad, dir, tile);
                    }
                }
                else
                {
                    UpdateTile(quad, OrthoDirExtensions.DirectionOf3D(quad.normal), tile);
                }
            }
        }
        RepaintMesh();
        primarySelection = GetSelectedQuad();
        CaptureSelection(primarySelection);

        PrefabStage prefabStage = PrefabStageUtility.GetPrefabStage(terrain.gameObject);

        if (prefabStage != null)
        {
            EditorSceneManager.MarkSceneDirty(prefabStage.scene);
        }
    }
コード例 #28
0
        private void DoDirty()
        {
            if (_button == null)
            {
                return;
            }
            var prefabStage = PrefabStageUtility.GetPrefabStage(_button.gameObject);

            if (prefabStage != null)
            {
                EditorSceneManager.MarkSceneDirty(prefabStage.scene);
            }
        }
コード例 #29
0
        /// <summary>
        /// Get the hierarchy path of a GameObject possibly including the scene name.
        /// </summary>
        /// <param name="gameObject">GameObject to extract a path from.</param>
        /// <param name="includeScene">If true, will append the scene name to the path.</param>
        /// <returns>Returns the path of a GameObject.</returns>
        public static string GetHierarchyPath(GameObject gameObject, bool includeScene = true)
        {
            if (gameObject == null)
            {
                return(String.Empty);
            }

            StringBuilder sb;

            if (_SbPool.Count > 0)
            {
                sb = _SbPool.Pop();
                sb.Clear();
            }
            else
            {
                sb = new StringBuilder(200);
            }

            try
            {
                if (includeScene)
                {
                    var sceneName = gameObject.scene.name;
                    if (sceneName == string.Empty)
                    {
                        var prefabStage = PrefabStageUtility.GetPrefabStage(gameObject);
                        if (prefabStage != null)
                        {
                            sceneName = "Prefab Stage";
                        }
                        else
                        {
                            sceneName = "Unsaved Scene";
                        }
                    }

                    sb.Append("<b>" + sceneName + "</b>");
                }

                sb.Append(GetTransformPath(gameObject.transform));

                var path = sb.ToString();
                sb.Clear();
                return(path);
            }
            finally
            {
                _SbPool.Push(sb);
            }
        }
コード例 #30
0
    public void UpdateAssetGuid()
    {
        // Set type guid
        var stage = PrefabStageUtility.GetPrefabStage(gameObject);

        if (stage != null)
        {
            var guidStr = AssetDatabase.AssetPathToGUID(stage.prefabAssetPath);
            if (SetAssetGUID(guidStr))
            {
                EditorSceneManager.MarkSceneDirty(stage.scene);
            }
        }
    }