public static void CheckUndo(Object[] target, string description = "Undo Audio Change") { src = null; srcObjs = target; Event e = Event.current; if (e.type == EventType.MouseDown && e.button == 0 || e.type == EventType.KeyUp && (e.keyCode == KeyCode.Tab)) { // When the LMB is pressed or the TAB key is released, // store a snapshot, but don't register it as an undo // ( so that if nothing changes we avoid storing a useless undo) Undo.SetSnapshotTarget(srcObjs, description); Undo.CreateSnapshot(); Undo.ClearSnapshotTarget(); listeningForGuiChanges = true; guiChanged = false; } if (listeningForGuiChanges && guiChanged) { // Some GUI value changed after pressing the mouse. // Register the previous snapshot as a valid undo. Undo.SetSnapshotTarget(srcObjs, description); Undo.RegisterSnapshot(); Undo.ClearSnapshotTarget(); listeningForGuiChanges = false; } }
/// <summary> /// Call this method BEFORE any undoable UnityGUI call. /// Manages undo for the given target, with the given name. /// </summary> /// <param name="target"> /// The <see cref="Object"/> you want to save undo info for. /// </param> /// <param name="name"> /// The name of the thing to undo (displayed as "Undo [name]" in the main menu). /// </param> public void CheckUndo(Object target, string name) { if (_waitingToRecordPrefab != null) { // Record eventual prefab instance modification. // TODO Avoid recording if nothing changed (no harm in doing so, but it would be nicer). switch (Event.current.type) { case EventType.MouseDown: case EventType.MouseUp: case EventType.KeyDown: case EventType.KeyUp: PrefabUtility.RecordPrefabInstancePropertyModifications(_waitingToRecordPrefab); break; } } if ((Event.current.type == EventType.MouseDown && Event.current.button == 0) || (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Tab)) { // When the LMB is pressed or the TAB key is released, // store a snapshot, but don't register it as an undo // (so that if nothing changes we avoid storing a useless undo). Undo.SetSnapshotTarget(target, name); Undo.CreateSnapshot(); Undo.ClearSnapshotTarget(); // Not sure if this is necessary. _listeningForGuiChanges = true; } }
// OnInspectorGUI public override void OnInspectorGUI() { GUI.color = Color.white; Undo.SetSnapshotTarget(m_Component, "OVRPlayerController"); { m_Component.Acceleration = EditorGUILayout.Slider("Acceleration", m_Component.Acceleration, 0, 1); m_Component.Damping = EditorGUILayout.Slider("Damping", m_Component.Damping, 0, 1); m_Component.BackAndSideDampen = EditorGUILayout.Slider("Back and Side Dampen", m_Component.BackAndSideDampen, 0, 1); // m_Component.JumpForce = EditorGUILayout.Slider("Jump Force", m_Component.JumpForce, 0, 10); m_Component.RotationAmount = EditorGUILayout.Slider("Rotation Amount", m_Component.RotationAmount, 0, 5); m_Component.DirXform = EditorGUILayout.ObjectField("Hip Direction", m_Component.DirXform, typeof(Transform), true) as Transform; OVREditorGUIUtility.Separator(); m_Component.GravityModifier = EditorGUILayout.Slider("Gravity Modifier", m_Component.GravityModifier, 0, 1); OVREditorGUIUtility.Separator(); } if (GUI.changed) { Undo.CreateSnapshot(); Undo.RegisterSnapshot(); EditorUtility.SetDirty(m_Component); } Undo.ClearSnapshotTarget(); }
// OnInspectorGUI public override void OnInspectorGUI() { GUI.color = Color.white; #pragma warning disable 0618 Undo.SetSnapshotTarget(m_Component, "OVRPlayerController"); #pragma warning restore 0618 { m_Component.Acceleration = EditorGUILayout.Slider("Acceleration", m_Component.Acceleration, 0, 1); m_Component.Damping = EditorGUILayout.Slider("Damping", m_Component.Damping, 0, 1); m_Component.BackAndSideDampen = EditorGUILayout.Slider("Back and Side Dampen", m_Component.BackAndSideDampen, 0, 1); // m_Component.JumpForce = EditorGUILayout.Slider("Jump Force", m_Component.JumpForce, 0, 10); m_Component.RotationAmount = EditorGUILayout.Slider("Rotation Amount", m_Component.RotationAmount, 0, 5); OVREditorGUIUtility.Separator(); m_Component.GravityModifier = EditorGUILayout.Slider("Gravity Modifier", m_Component.GravityModifier, 0, 1); OVREditorGUIUtility.Separator(); } if (GUI.changed) { #pragma warning disable 0618 Undo.CreateSnapshot(); Undo.RegisterSnapshot(); EditorUtility.SetDirty(m_Component); } Undo.ClearSnapshotTarget(); #pragma warning restore 0618 }
//~ [MenuItem ("TDTK/LayerEditor")] //~ static void Init(){ //~ // Get existing open window or if none, make a new one: //~ window = (LayerEditor)EditorWindow.GetWindow(typeof (LayerEditor)); //~ window.minSize=new Vector2(300, 300); //~ layerCreep=PlayerPrefs .GetInt("CreepLayer", 31); //~ layerCreepF=PlayerPrefs .GetInt("CreepFLayer", 30); //~ layerTower=PlayerPrefs .GetInt("TowerLayer", 29); //~ layerPlatform=PlayerPrefs .GetInt("PlatformLayer", 28); //~ GetSpawnManager(); //~ } public override void OnInspectorGUI() { LayerManager lm = (LayerManager)target; Undo.SetSnapshotTarget(lm, "LayerManager"); GUI.changed = false; lm.layerCreep = EditorGUILayout.LayerField("Creep Layer:", lm.layerCreep); lm.layerCreepF = EditorGUILayout.LayerField("CreepF Layer:", lm.layerCreepF); lm.layerTower = EditorGUILayout.LayerField("Tower Layer:", lm.layerTower); lm.layerPlatform = EditorGUILayout.LayerField("Platform Layer:", lm.layerPlatform); lm.layerOverlay = EditorGUILayout.LayerField("Overlay Layer:", lm.layerOverlay); lm.layerMiscUI = EditorGUILayout.LayerField("Misc UI Layer:", lm.layerMiscUI); lm.layerTerrain = EditorGUILayout.LayerField("Terrain/Cam Layer:", lm.layerTerrain); //~ lm.layerCreep=Mathf.Clamp(lm.layerCreep, 0, 31); //~ lm.layerCreepF=Mathf.Clamp(lm.layerCreepF, 0, 31); //~ lm.layerTower=Mathf.Clamp(lm.layerTower, 0, 31); //~ lm.layerPlatform=Mathf.Clamp(lm.layerPlatform, 0, 31); if (GUI.changed) { EditorUtility.SetDirty(lm); Undo.CreateSnapshot(); Undo.RegisterSnapshot(); } Undo.ClearSnapshotTarget(); }
// OnInspectorGUI public override void OnInspectorGUI() { GUI.color = Color.white; Undo.SetSnapshotTarget(m_Component, "OVRCameraController"); { /* * m_Component.NeckPosition = EditorGUILayout.Vector3Field("Neck Position", m_Component.NeckPosition); * m_Component.EyeCenterPosition = EditorGUILayout.Vector3Field("Eye Center Position", m_Component.EyeCenterPosition); * OVREditorGUIUtility.Separator(); * m_Component.TrackerRotatesY = EditorGUILayout.Toggle("Tracker Rotates Y", m_Component.TrackerRotatesY); * OVREditorGUIUtility.Separator(); * m_Component.BackgroundColor = EditorGUILayout.ColorField("Background Color", m_Component.BackgroundColor); * OVREditorGUIUtility.Separator(); */ DrawDefaultInspector(); } if (GUI.changed) { Undo.CreateSnapshot(); Undo.RegisterSnapshot(); EditorUtility.SetDirty(target); } Undo.ClearSnapshotTarget(); }
// OnInspectorGUI public override void OnInspectorGUI() { GUI.color = Color.white; Undo.SetSnapshotTarget(m_Component, "OVRCameraController"); { #if CUSTOM_LAYOUT OVREditorGUIUtility.Separator(); m_Component.VerticalFOV = EditorGUILayout.FloatField("Vertical FOV", m_Component.VerticalFOV); m_Component.IPD = EditorGUILayout.FloatField("IPD", m_Component.IPD); OVREditorGUIUtility.Separator(); m_Component.CameraRootPosition = EditorGUILayout.Vector3Field("Camera Root Position", m_Component.CameraRootPosition); m_Component.NeckPosition = EditorGUILayout.Vector3Field("Neck Position", m_Component.NeckPosition); m_Component.EyeCenterPosition = EditorGUILayout.Vector3Field("Eye Center Position", m_Component.EyeCenterPosition); OVREditorGUIUtility.Separator(); m_Component.UsePlayerEyeHeight = EditorGUILayout.Toggle("Use Player Eye Height", m_Component.UsePlayerEyeHeight); OVREditorGUIUtility.Separator(); m_Component.FollowOrientation = EditorGUILayout.ObjectField("Follow Orientation", m_Component.FollowOrientation, typeof(Transform), true) as Transform; m_Component.TrackerRotatesY = EditorGUILayout.Toggle("Tracker Rotates Y", m_Component.TrackerRotatesY); OVREditorGUIUtility.Separator(); // Remove Portrait Mode from Inspector window for now //m_Component.PortraitMode = EditorGUILayout.Toggle ("Portrait Mode", m_Component.PortraitMode); m_Component.PredictionOn = EditorGUILayout.Toggle("Prediction On", m_Component.PredictionOn); m_Component.CallInPreRender = EditorGUILayout.Toggle("Call in Pre-Render", m_Component.CallInPreRender); m_Component.WireMode = EditorGUILayout.Toggle("Wire-Frame Mode", m_Component.WireMode); m_Component.LensCorrection = EditorGUILayout.Toggle("Lens Correction", m_Component.LensCorrection); m_Component.Chromatic = EditorGUILayout.Toggle("Chromatic", m_Component.Chromatic); OVREditorGUIUtility.Separator(); #else DrawDefaultInspector(); #endif } if (GUI.changed) { Undo.CreateSnapshot(); Undo.RegisterSnapshot(); EditorUtility.SetDirty(m_Component); } Undo.ClearSnapshotTarget(); }
/// <summary> /// Call this method AFTER any undoable UnityGUI call. /// Forces undo for the given target, with the given name. /// Used to undo operations that are performed by pressing a button, /// which doesn't set the GUI to a changed state. /// </summary> /// <param name="target"> /// The <see cref="Object"/> you want to save undo info for. /// </param> /// <param name="name"> /// The name of the thing to undo (displayed as "Undo [name]" in the main menu). /// </param> public void ForceDirty(Object target, string name) { if (!_listeningForGuiChanges) { // Create a new snapshot. Undo.SetSnapshotTarget(target, name); Undo.CreateSnapshot(); Undo.ClearSnapshotTarget(); } SetDirty(target, name, true); }
public void ForceDirty(Object p_target, string p_name) { if (!listeningForGuiChanges) { // Create a new snapshot. Undo.SetSnapshotTarget(p_target, p_name); Undo.CreateSnapshot(); Undo.ClearSnapshotTarget(); } SetDirty(p_target, p_name); }
private void OnGUI() { ValidateGUIStyles(); if (_inputManager == null && !_tryedToFindInputManagerInScene) { TryToFindInputManagerInScene(); } if (_inputManager == null) { DisplayMissingInputManagerWarning(); return; } #if UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 Undo.SetSnapshotTarget(_inputManager, "InputManager"); Undo.CreateSnapshot(); #else Undo.RecordObject(_inputManager, "InputManager"); #endif UpdateHierarchyPanelWidth(); if (_searchString.Length > 0) { DisplaySearchResults(); } else { DisplayHierarchyPanel(); } if (_selectionPath.Count >= 1) { DisplayMainPanel(); } DisplayMainToolbar(); #if UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 if (GUI.changed) { Undo.RegisterSnapshot(); EditorUtility.SetDirty(_inputManager); } Undo.ClearSnapshotTarget(); #else if (GUI.changed) { EditorUtility.SetDirty(_inputManager); } #endif }
/// <summary> /// Call this method BEFORE any undoable UnityGUI call. /// Manages undo for the given target, with the given name. /// </summary> /// <param name="p_target"> /// The <see cref="Object"/> you want to save undo info for. /// </param> /// <param name="p_name"> /// The name of the thing to undo (displayed as "Undo [name]" in the main menu). /// </param> public void CheckUndo(Object p_target, string p_name) { Event e = Event.current; if ((e.type == EventType.MouseDown && e.button == 0) || (e.type == EventType.KeyUp && e.keyCode == KeyCode.Tab)) { // When the LMB is pressed or the TAB key is released, // store a snapshot, but don't register it as an undo // (so that if nothing changes we avoid storing a useless undo). Undo.SetSnapshotTarget(p_target, p_name); Undo.CreateSnapshot(); Undo.ClearSnapshotTarget(); // Not sure if this is necessary. listeningForGuiChanges = true; } }
public override void OnInspectorGUI() { Undo.SetSnapshotTarget(rm, "ResourceManager"); GUI.changed = false; EditorGUILayout.Space(); //num=EditorGUILayout.IntField("Total ResourceType: ", num); //if(num<=0) num=1; //EditorGUILayout.Space(); //if(num!=rm.resources.Length) UpdateResourceSize(num); if (foldList.Count != rm.resources.Length) { UpdateFoldListSize(); } for (int i = 0; i < rm.resources.Length; i++) { if (rm.resources[i] != null) { foldList[i] = EditorGUILayout.Foldout(foldList[i], rm.resources[i].name + ": " + rm.resources[i].value); if (foldList[i]) { GUILayout.BeginHorizontal(); GUILayout.Label(rm.resources[i].icon, GUILayout.Width(43), GUILayout.Height(43)); GUILayout.BeginVertical(); GUILayout.Label(rm.resources[i].name); rm.resources[i].value = EditorGUILayout.IntField("Start Value: ", rm.resources[i].value); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } } } if (GUI.changed) { EditorUtility.SetDirty(rm); Undo.CreateSnapshot(); Undo.RegisterSnapshot(); } Undo.ClearSnapshotTarget(); }
public void VerifyingList() { Undo.SetSnapshotTarget(pm, "PerkManager"); List <Perk> list = PerkEditorWindow.Load(); int n = 0; foreach (Perk perk in pm.allPerkList) { if (perk.enableInlvl) { n += 1; } } int m = 0; foreach (Perk perk in list) { if (perk.enableInlvl) { m += 1; } } for (int i = 0; i < list.Count; i++) { Perk perk = list[i]; foreach (Perk p in pm.allPerkList) { if (perk.ID == p.ID) { //~ if(perk.name=="CanonTower") Debug.Log(perk.name+" "+p.unlocked); //~ Debug.Log(p.ID+" "+p.name+" "+p.enableInlvl); perk.enableInlvl = p.enableInlvl; perk.unlocked = p.unlocked; } } } pm.allPerkList = list; EditorUtility.SetDirty(pm); Undo.CreateSnapshot(); Undo.RegisterSnapshot(); Undo.ClearSnapshotTarget(); }
// OnInspectorGUI public override void OnInspectorGUI() { GUI.color = Color.white; Undo.SetSnapshotTarget(m_Component, "OVRCameraController"); { #if CUSTOM_LAYOUT m_Component.NeckPosition = EditorGUILayout.Vector3Field("Neck Position", m_Component.NeckPosition); m_Component.EyeCenterPosition = EditorGUILayout.Vector3Field("Eye Center Position", m_Component.EyeCenterPosition); OVREditorGUIUtility.Separator(); m_Component.FollowOrientation = EditorGUILayout.ObjectField("Follow Orientation", m_Component.FollowOrientation, typeof(Transform), true) as Transform; m_Component.TrackerRotatesY = EditorGUILayout.Toggle("Tracker Rotates Y", m_Component.TrackerRotatesY); OVREditorGUIUtility.Separator(); m_Component.PredictionOn = EditorGUILayout.Toggle("Prediction On", m_Component.PredictionOn); m_Component.CallInPreRender = EditorGUILayout.Toggle("Call in Pre-Render", m_Component.CallInPreRender); m_Component.WireMode = EditorGUILayout.Toggle("Wire-Frame Mode", m_Component.WireMode); m_Component.LensCorrection = EditorGUILayout.Toggle("Lens Correction", m_Component.LensCorrection); m_Component.Chromatic = EditorGUILayout.Toggle("Chromatic", m_Component.Chromatic); OVREditorGUIUtility.Separator(); m_Component.BackgroundColor = EditorGUILayout.ColorField("Background Color", m_Component.BackgroundColor); m_Component.NearClipPlane = EditorGUILayout.FloatField("Near Clip Plane", m_Component.NearClipPlane); m_Component.FarClipPlane = EditorGUILayout.FloatField("Far Clip Plane", m_Component.FarClipPlane); OVREditorGUIUtility.Separator(); #else DrawDefaultInspector(); #endif } if (GUI.changed) { Undo.CreateSnapshot(); Undo.RegisterSnapshot(); EditorUtility.SetDirty(m_Component); } Undo.ClearSnapshotTarget(); }
private void OnGUI() { if (_inputManager == null) { return; } if (_configurationFoldouts.Count != _inputManager.inputConfigurations.Count) { UpdateFoldouts(); } #if UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 Undo.SetSnapshotTarget(_inputManager, "InputManager"); Undo.CreateSnapshot(); #else Undo.RecordObject(_inputManager, "InputManager"); #endif UpdateHierarchyPanelWidth(); if (_searchString.Length > 0) { DisplaySearchResults(); } else { DisplayHierarchyPanel(); } if (_selectionPath.Count >= 1) { DisplayMainPanel(); } DisplayMainToolbar(); #if UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 if (GUI.changed) { Undo.RegisterSnapshot(); EditorUtility.SetDirty(_inputManager); } Undo.ClearSnapshotTarget(); #else if (GUI.changed) { EditorUtility.SetDirty(_inputManager); } #endif Repaint(); }
/// <summary> /// Call this method AFTER any undoable UnityGUI call. /// Manages undo for the given target, with the given name. /// </summary> /// <param name="p_target"> /// The <see cref="Object"/> you want to save undo info for. /// </param> /// <param name="p_name"> /// The name of the thing to undo (displayed as "Undo [name]" in the main menu). /// </param> public void CheckDirty(Object p_target, string p_name) { if (listeningForGuiChanges && GUI.changed) { // Some GUI value changed after pressing the mouse // or releasing the TAB key. // Register the previous snapshot as a valid undo. Undo.SetSnapshotTarget(p_target, p_name); Undo.RegisterSnapshot(); Undo.ClearSnapshotTarget(); // Not sure if this is necessary. if (autoSetDirty) { EditorUtility.SetDirty(p_target); } listeningForGuiChanges = false; } }
public static void Draw(AudioBus node) { checkMouse(node); EditorGUILayout.BeginVertical(); node.Name = EditorGUILayout.TextField("Name", node.Name); Undo.ClearSnapshotTarget(); checkMouse(node); //In AuxWindow, update all bus volumes node.Volume = EditorGUILayout.Slider("Volume", node.Volume, 0.0f, 1.0f); Undo.ClearSnapshotTarget(); GUI.enabled = false; checkMouse(node); EditorGUILayout.Slider("Combined Volume", node.CombinedVolume, 0, 1.0f); GUI.enabled = true; EditorGUILayout.EndVertical(); //Undo.ClearSnapshotTarget(); }
private void CheckUndo() { #if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0 Event e = Event.current; if (e.type == EventType.MouseDown && e.button == 0 || e.type == EventType.KeyUp && (e.keyCode == KeyCode.Tab)) { //Debug.Log("record1"); Undo.RecordObject(_ProFlareAtlas, "ProFlareAtlas Undo"); listeningForGuiChanges = true; guiChanged = false; } if (listeningForGuiChanges && guiChanged) { //Debug.Log("record2"); Undo.RecordObject(_ProFlareAtlas, "ProFlareAtlas Undo"); listeningForGuiChanges = false; } #else Event e = Event.current; if (e.type == EventType.MouseDown && e.button == 0 || e.type == EventType.KeyUp && (e.keyCode == KeyCode.Tab)) { Undo.SetSnapshotTarget(_ProFlareAtlas, "ProFlareAtlas Undo"); Undo.CreateSnapshot(); Undo.ClearSnapshotTarget(); listeningForGuiChanges = true; guiChanged = false; } if (listeningForGuiChanges && guiChanged) { Undo.SetSnapshotTarget(_ProFlareAtlas, "ProFlareAtlas Undo"); Undo.RegisterSnapshot(); Undo.ClearSnapshotTarget(); listeningForGuiChanges = false; } #endif }
private void CheckUndo() { Event e = Event.current; if (e.type == EventType.MouseDown && e.button == 0 || e.type == EventType.KeyUp && (e.keyCode == KeyCode.Tab)) { Undo.SetSnapshotTarget(scrollLayer, "Change Scroll Layer Properties"); Undo.CreateSnapshot(); Undo.ClearSnapshotTarget(); listeningForGuiChanges = true; guiChanged = false; } if (listeningForGuiChanges && guiChanged) { Undo.SetSnapshotTarget(scrollLayer, "Change Scroll Layer Properties"); Undo.RegisterSnapshot(); Undo.ClearSnapshotTarget(); listeningForGuiChanges = false; } }
public void VerifyingList() { Undo.SetSnapshotTarget(am, "AbilityManager"); List <Ability> list = AbilityEditorWindow.Load(); for (int i = 0; i < list.Count; i++) { list[i] = list[i].Clone(); } //~ int n=0; //~ foreach(Ability ability in am.allAbilityList){ //~ if(ability.enableInlvl) n+=1; //~ } //~ int m=0; //~ foreach(Ability ability in list){ //~ if(ability.enableInlvl) m+=1; //~ } for (int i = 0; i < list.Count; i++) { Ability ability = list[i]; foreach (Ability a in am.allAbilityList) { if (ability.ID == a.ID) { ability.enableInlvl = a.enableInlvl; } } } am.allAbilityList = list; EditorUtility.SetDirty(am); Undo.CreateSnapshot(); Undo.RegisterSnapshot(); Undo.ClearSnapshotTarget(); }
public bool OnGUI(int leftWidth, int height) { BaseOnGUI(); var dataManager = InstanceFinder.DataManager; if (dataManager != null) { Undo.ClearSnapshotTarget(); var root = dataManager.BankLinkTree; int id = InstanceFinder.GuiUserPrefs.SelectedBusID; var selectedNode = UpdateSelectedNode(root, id); InstanceFinder.GuiUserPrefs.SelectedBusID = selectedNode != null ? selectedNode.ID : 0; } this.leftWidth = leftWidth; this.height = height; EditorGUIHelper.DrawColums(DrawLeftSide, DrawRightSide); return(isDirty); }
private void CheckUndo() { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 Event e = Event.current; if (e.type == EventType.MouseDown && e.button == 0 || e.type == EventType.KeyUp && (e.keyCode == KeyCode.Tab)) { Undo.SetSnapshotTarget(new Object[] { target, this }, "Modify Delay"); Undo.CreateSnapshot(); Undo.ClearSnapshotTarget(); listeningForGuiChanges = true; guiChanged = false; } if (listeningForGuiChanges && guiChanged) { Undo.SetSnapshotTarget(new Object[] { target, this }, "Modify Delay"); Undo.RegisterSnapshot(); Undo.ClearSnapshotTarget(); listeningForGuiChanges = false; } #endif }
// =================================================================================== // METHODS --------------------------------------------------------------------------- void SetDirty(Object target, string name, bool force = false) { Undo.SetSnapshotTarget(target, name); Undo.RegisterSnapshot(); Undo.ClearSnapshotTarget(); // Not sure if this is necessary. if (_AutoSetDirty || force) { EditorUtility.SetDirty(target); } _listeningForGuiChanges = false; if (CheckTargetIsPrefabInstance(target)) { // Prefab instance: record immediately and also wait for value to be changed and than re-record it // (otherwise prefab instances are not updated correctly when using Custom Inspectors). PrefabUtility.RecordPrefabInstancePropertyModifications(target); _waitingToRecordPrefab = target; } else { _waitingToRecordPrefab = null; } }
void OnGUI() { if (material == null) { return; } // if this was an undo, repaint it if (Event.current.type == EventType.ValidateCommand) { switch (Event.current.commandName) { case "UndoRedoPerformed": Repaint(); return; } } #if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0) Undo.RecordObject(material, "Modified Terrain Material"); #else Undo.SetSnapshotTarget(material, "Modified Terrain Material"); if (!Ferr_EditorTools.HandlesMoving()) { Undo.CreateSnapshot(); } #endif if (Ferr_EditorTools.ResetHandles()) { GUI.changed = true; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(GUILayout.Width(width)); Ferr_EditorTools.Box(5, () => { if (currDir != Ferr2DT_TerrainDirection.None) { Ferr2DT_TerrainMaterialUtility.ShowSample(material, currDir, width - 10); } Ferr_EditorTools.Box(2, () => { if (GUILayout.Button("Top")) { currDir = Ferr2DT_TerrainDirection.Top; } if (currDir == Ferr2DT_TerrainDirection.Top) { if (prevDir != currDir) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor(currDir)); } bool showTop = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Top), "Use Top"); material.Set(Ferr2DT_TerrainDirection.Top, showTop); if (showTop) { ShowDirection(material, currDir); } } }, width - 10); Ferr_EditorTools.Box(2, () => { if (GUILayout.Button("Left")) { currDir = Ferr2DT_TerrainDirection.Left; } if (currDir == Ferr2DT_TerrainDirection.Left) { if (prevDir != currDir) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor(currDir)); } bool showLeft = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Left), "Use Left"); material.Set(Ferr2DT_TerrainDirection.Left, showLeft); if (showLeft) { ShowDirection(material, currDir); } } }, width - 10); Ferr_EditorTools.Box(2, () => { if (GUILayout.Button("Right")) { currDir = Ferr2DT_TerrainDirection.Right; } if (currDir == Ferr2DT_TerrainDirection.Right) { if (prevDir != currDir) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor(currDir)); } bool showRight = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Right), "Use Right"); material.Set(Ferr2DT_TerrainDirection.Right, showRight); if (showRight) { ShowDirection(material, currDir); } } }, width - 10); Ferr_EditorTools.Box(2, () => { if (GUILayout.Button("Bottom")) { currDir = Ferr2DT_TerrainDirection.Bottom; } if (currDir == Ferr2DT_TerrainDirection.Bottom) { if (prevDir != currDir) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor(currDir)); } bool showBottom = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Bottom), "Use Bottom"); material.Set(Ferr2DT_TerrainDirection.Bottom, showBottom); if (showBottom) { ShowDirection(material, currDir); } } }, width - 10); }, 0, (int)this.position.height); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); scroll = EditorGUILayout.BeginScrollView(scroll); if (currDir != Ferr2DT_TerrainDirection.None) { Ferr2DT_TerrainMaterialUtility.ShowPreview(material, currDir, simpleUVs, true, width); } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); if (Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDrag) { Repaint(); } if (GUI.changed) { EditorUtility.SetDirty(material); #if (UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0) Undo.RegisterSnapshot(); #endif Ferr2DT_PathTerrain[] terrain = GameObject.FindObjectsOfType(typeof(Ferr2DT_PathTerrain)) as Ferr2DT_PathTerrain[]; for (int i = 0; i < terrain.Length; i++) { if (terrain[i].TerrainMaterial == material) { terrain[i].RecreatePath(true); } } } #if (UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0) Undo.ClearSnapshotTarget(); #endif prevDir = currDir; }
private void UpdatePoseEditGUI(Event a_rEvent) { //Transform rRootTransform = Selection.activeTransform; Vector2 f2MouseGUIPos = a_rEvent.mousePosition; if (a_rEvent.isMouse) { int iMouseButton = a_rEvent.button; switch (a_rEvent.type) { case EventType.MouseMove: { // Reset state m_bIsDragging = false; // Something selected, edit tool used => move bone if (Uni2DEditorSmoothBindingGUI.activeBone != null && ms_eEditorTool != BoneEditorTool.Select) { Uni2DEditorSmoothBindingGUI.activeBone.MoveBoneAlongSpritePlane(f2MouseGUIPos - m_f2MouseGUIOffset, a_rEvent.alt); } // Consume event a_rEvent.Use( ); } break; // End MouseMove case EventType.MouseDown: { // Left click if (iMouseButton == 0) { // Reset drag state m_bIsDragging = false; // Selection if (ms_eEditorTool == BoneEditorTool.Select) { // Pick bones in scene BoneHandle ePickedHandle; Uni2DSmoothBindingBone rNearestBone = Uni2DEditorSmoothBindingUtils.PickNearestBoneInPosingMode(ms_rSprite, f2MouseGUIPos, out ePickedHandle, null); // Outer disc => move if (ePickedHandle == BoneHandle.OuterDisc || ePickedHandle == BoneHandle.Link) { if (rNearestBone != null) { // Change selection and editor tool Uni2DEditorSmoothBindingGUI.activeBone = rNearestBone; ms_eEditorTool = BoneEditorTool.Move; m_f2MouseGUIOffset = f2MouseGUIPos - HandleUtility.WorldToGUIPoint(rNearestBone.transform.position); } } else // Bone picked via inner disc or no bone picked { // A bone has been picked (via inner disc) // Set selection to this bone if (rNearestBone != null) { Uni2DEditorSmoothBindingGUI.activeBone = rNearestBone; } else // No bone picked { // Get rid of selection if any if (Uni2DEditorSmoothBindingGUI.activeBone != null) { Uni2DEditorSmoothBindingGUI.activeBone = null; } else // no selection, no bone picked => create a new bone chain { m_rLastAddedBone = null; // Create a new root and set it as current active bone Uni2DEditorSmoothBindingGUI.activeBone = Uni2DEditorSmoothBindingUtils.AddBoneToSprite(ms_rSprite, f2MouseGUIPos, null); m_rBoneChainOrigin = Uni2DEditorSmoothBindingGUI.activeBone; // The bone is not a child of a newly created root //m_bStartFromExistingBone = false; // Change editor tool ms_eEditorTool = BoneEditorTool.Create; } } } } // end if( editor tool == select ) } // Consume mouse event a_rEvent.Use( ); } break; // end MouseDown case EventType.MouseDrag: { if (iMouseButton == 0) { switch (ms_eEditorTool) { case BoneEditorTool.Move: { // Something dragged? MOVE IT if (Uni2DEditorSmoothBindingGUI.activeBone != null) { // We're moving an existing bone => register undo at first drag event if (m_bIsDragging == false) { #if BEFORE_UNITY_4_3 Undo.SetSnapshotTarget(Uni2DEditorSmoothBindingGUI.activeBone, "Move Uni2D Bone"); Undo.CreateSnapshot( ); Undo.RegisterSnapshot( ); #else Uni2DUndo.RegisterFullObjectHierarchyUndo(ms_rSprite.gameObject, "Move Uni2D Bone"); #endif } // Move/drag along sprite plane; Uni2DEditorSmoothBindingGUI.activeBone.MoveBoneAlongSpritePlane(f2MouseGUIPos - m_f2MouseGUIOffset, a_rEvent.alt); } m_bIsDragging = true; } break; case BoneEditorTool.Select: { // Dragging a bone in select mode == dragging on inner disc => add a child to active bone if (Uni2DEditorSmoothBindingGUI.activeBone != null && m_bIsDragging == false) { m_rBoneChainOrigin = Uni2DEditorSmoothBindingGUI.activeBone; m_rLastAddedBone = null; Uni2DEditorSmoothBindingGUI.activeBone = Uni2DEditorSmoothBindingUtils.AddBoneToSprite(ms_rSprite, f2MouseGUIPos, Uni2DEditorSmoothBindingGUI.activeBone); //m_bStartFromExistingBone = true; ms_eEditorTool = BoneEditorTool.Create; } m_bIsDragging = true; } break; case BoneEditorTool.Create: { if (Uni2DEditorSmoothBindingGUI.activeBone != null) { Uni2DEditorSmoothBindingGUI.activeBone.MoveBoneAlongSpritePlane(f2MouseGUIPos); } m_bIsDragging = true; } break; } } // Consume event a_rEvent.Use( ); } break; // End MouseDrag case EventType.MouseUp: { if (iMouseButton == 0) { switch (ms_eEditorTool) { // Creation case BoneEditorTool.Create: { BoneHandle ePickedHandle; Uni2DSmoothBindingBone rNearestBone = Uni2DEditorSmoothBindingUtils.PickNearestBoneInPosingMode(ms_rSprite, f2MouseGUIPos, out ePickedHandle, Uni2DEditorSmoothBindingGUI.activeBone); // Mouse up near the last added bone => close bone chain if (ePickedHandle == BoneHandle.InnerDisc && rNearestBone == m_rLastAddedBone) { Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone); m_rLastAddedBone = null; Uni2DEditorSmoothBindingGUI.activeBone = null; ms_eEditorTool = BoneEditorTool.Select; } else { m_rLastAddedBone = Uni2DEditorSmoothBindingGUI.activeBone; Undo.RegisterCreatedObjectUndo(m_rLastAddedBone.gameObject, "Add Uni2D Bone"); // Creating => validate bone and create another one Uni2DEditorSmoothBindingGUI.activeBone = Uni2DEditorSmoothBindingUtils.AddBoneToSprite(ms_rSprite, f2MouseGUIPos, m_rLastAddedBone); } } break; // Move case BoneEditorTool.Move: { #if BEFORE_UNITY_4_3 Undo.ClearSnapshotTarget( ); Undo.RegisterSnapshot( ); #endif ms_eEditorTool = BoneEditorTool.Select; } break; } // Reset dragging state m_bIsDragging = false; m_f2MouseGUIOffset = Vector2.zero; } // end if( left button ) else if (iMouseButton == 1) // Delete / stop bone creation { switch (ms_eEditorTool) { case BoneEditorTool.Select: { BoneHandle eBoneHandle; Uni2DSmoothBindingBone rNearestBone = Uni2DEditorSmoothBindingUtils.PickNearestBoneInPosingMode(ms_rSprite, f2MouseGUIPos, out eBoneHandle, null); if (rNearestBone != null) { if (eBoneHandle == BoneHandle.Link) { //Undo.RegisterSetTransformParentUndo( rNearestBone.transform, rRootTransform, "Break Uni2D Bone" ); rNearestBone.Break( ); } else { #if BEFORE_UNITY_4_3 Undo.RegisterSceneUndo("Delete Uni2D Bone"); #else Uni2DUndo.RegisterFullObjectHierarchyUndo(ms_rSprite.gameObject, "Delete Uni2D Bone"); #endif Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, rNearestBone); } } } break; case BoneEditorTool.Create: { // Close bone chain Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone); ms_eEditorTool = BoneEditorTool.Select; } break; case BoneEditorTool.Move: { ms_eEditorTool = BoneEditorTool.Select; } break; } } // End if( right button ) // Consume event a_rEvent.Use( ); } break; // End MouseUp } // End switch( event.type ) } // end if( mouse events ) else if (a_rEvent.isKey && a_rEvent.type == EventType.keyDown) { switch (a_rEvent.keyCode) { case KeyCode.Escape: { switch (ms_eEditorTool) { case BoneEditorTool.Select: { if (Uni2DEditorSmoothBindingGUI.activeBone != null) { Uni2DEditorSmoothBindingGUI.activeBone = null; } else { Uni2DEditorSmoothBindingGUI.CurrentBoneEditMode = BoneEditMode.None; } } break; case BoneEditorTool.Move: { #if BEFORE_UNITY_4_3 Undo.RestoreSnapshot( ); #endif ms_eEditorTool = BoneEditorTool.Select; } break; case BoneEditorTool.Create: { Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone); ms_eEditorTool = BoneEditorTool.Select; } break; } a_rEvent.Use( ); } break; // End Escape // Delete last created bone (if any) case KeyCode.Backspace: { if (ms_eEditorTool == BoneEditorTool.Create) { if (m_rLastAddedBone != null && m_rLastAddedBone != m_rBoneChainOrigin) { #if BEFORE_UNITY_4_3 Undo.RegisterSceneUndo("Delete Uni2D Bone"); #else Uni2DUndo.RegisterFullObjectHierarchyUndo(ms_rSprite.gameObject, "Delete Uni2D Bone"); #endif Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone); Uni2DEditorSmoothBindingGUI.activeBone = Uni2DEditorSmoothBindingUtils.AddBoneToSprite(ms_rSprite, f2MouseGUIPos, m_rLastAddedBone.Parent); Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, m_rLastAddedBone); Uni2DSmoothBindingBone rParentActiveBone = Uni2DEditorSmoothBindingGUI.activeBone.Parent; if (rParentActiveBone != null && rParentActiveBone.IsFakeRootBone) { m_rLastAddedBone = rParentActiveBone.Parent; // Grand-pa' } else { m_rLastAddedBone = rParentActiveBone; } } } a_rEvent.Use( ); } break; // End Escape case KeyCode.Return: case KeyCode.KeypadEnter: { ms_eEditorTool = BoneEditorTool.Select; a_rEvent.Use( ); } break; // End Return / KeypadEnter } // end switch( event.type ) } // end if( key down events ) else { switch (a_rEvent.type) { case EventType.ValidateCommand: { if (a_rEvent.commandName == "Delete" || a_rEvent.commandName == "UndoRedoPerformed") { a_rEvent.Use( ); } } break; // end ValidateCommand case EventType.ExecuteCommand: { if (a_rEvent.commandName == "Delete") { if (Uni2DEditorSmoothBindingGUI.activeBone != null && ms_eEditorTool != BoneEditorTool.Create) { #if BEFORE_UNITY_4_3 Undo.RegisterSceneUndo("Delete Uni2D Bone"); #else Uni2DUndo.RegisterFullObjectHierarchyUndo(ms_rSprite.gameObject, "Delete Uni2D Bone"); #endif Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone); ms_eEditorTool = BoneEditorTool.Select; } a_rEvent.Use( ); } else if (a_rEvent.commandName == "UndoRedoPerformed") { if (ms_eEditorTool == BoneEditorTool.Create && Uni2DEditorSmoothBindingGUI.activeBone != null) { Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone); } m_rLastAddedBone = null; Uni2DEditorSmoothBindingGUI.activeBone = null; ms_eEditorTool = BoneEditorTool.Select; //Uni2DEditorSmoothBindingGUI.CurrentBoneEditMode = BoneEditMode.None; a_rEvent.Use( ); } } break; // end ExecuteCommand } // end switch( event.type ) } // end else }
//~ string warning=""; //~ void Test(){ //~ string sourcePath=AssetDatabase.GetAssetPath(resourceList[1].icon); //~ string targetPath=Application.dataPath + "/TDTK/Resources/"; //~ if(AssetDatabase.LoadAssetAtPath(targetPath+resourceList[0].icon.name, typeof(Texture2D))==null){ //~ AssetDatabase.CopyAsset(sourcePath, targetPath); //~ } //~ AssetDatabase.Refresh(); //~ } //~ void ClearWarning(){ //~ warning=""; //~ } //~ void UpdateWarning(){ //~ warning="Please note that you need to save and refresh Resource\nManager in each scene for the new change to take effect."; //~ } void OnGUI() { if (window == null) { Init(); } Undo.SetSnapshotTarget(this, "ResourceEditor"); //~ if(towerList.Count%2==0) GUI.color=new Color(.8f, .8f, .8f, 1); //~ else GUI.color=Color.white; //~ GUI.Box(new Rect(5, 75+towerList.Count*49, window.position.width-10, 50), ""); //~ GUI.color=Color.white; EditorGUI.LabelField(new Rect(5, 10, 150, 17), "Add new tower:"); newTower = (UnitTower)EditorGUI.ObjectField(new Rect(100, 10, 160, 17), newTower, typeof(UnitTower), false); if (newTower != null) { if (!towerList.Contains(newTower)) { //~ if(!towerIDList.Contains(newTower.prefabID)) towerIDList.Add(newTower.prefabID); //~ else{ int rand = 0; while (towerIDList.Contains(rand)) { rand += 1; } towerIDList.Add(rand); newTower.prefabID = rand; //~ } towerList.Add(newTower); if (onTowerUpdateE != null) { onTowerUpdateE(); } } newTower = null; } //~ if(GUI.Button(new Rect(window.position.width-85, 10, 80, 30), "Save")){ //~ warning="Refresh ResourceManager in each scene for the new \nchange to take effect!"; //~ SaveToXML(); //~ } //~ if(GUI.Button(new Rect(10, 10, 100, 30), "New Resource")){ //~ UpdateWarning(); //~ towerList.Add(new UnitTower()); //~ } if (towerList.Count > 0) { GUI.Box(new Rect(5, 40, 50, 20), "ID"); GUI.Box(new Rect(5 + 50 - 1, 40, 60 + 1, 20), "Icon"); GUI.Box(new Rect(5 + 110 - 1, 40, 160 + 2, 20), "Name - Tower Type"); GUI.Box(new Rect(5 + 270, 40, window.position.width - 300, 20), ""); } scrollPos = GUI.BeginScrollView(new Rect(5, 60, window.position.width - 12, window.position.height - 50), scrollPos, new Rect(5, 55, window.position.width - 30, 15 + ((towerList.Count)) * 50)); int row = 0; for (int i = 0; i < towerList.Count; i++) { if (i % 2 == 0) { GUI.color = new Color(.8f, .8f, .8f, 1); } else { GUI.color = Color.white; } GUI.Box(new Rect(5, 60 + i * 49, window.position.width - 30, 50), ""); GUI.color = Color.white; //~ GUI.Label(new Rect(22, 15+60+i*49, 50, 20), towerList[i].prefabID.ToString()); if (currentSwapID == i) { GUI.color = new Color(.9f, .9f, .0f, 1); } if (GUI.Button(new Rect(19, 12 + 60 + i * 49, 30, 30), towerList[i].prefabID.ToString())) { if (currentSwapID == i) { currentSwapID = -1; } else if (currentSwapID == -1) { currentSwapID = i; } else { SwapTower(i); } } if (currentSwapID == i) { GUI.color = Color.white; } if (towerList[i] != null) { towerList[i].icon = (Texture)EditorGUI.ObjectField(new Rect(12 + 50, 3 + 60 + i * 49, 44, 44), towerList[i].icon, typeof(Texture), false); towerList[i].unitName = EditorGUI.TextField(new Rect(5 + 120, 6 + 60 + i * 49, 150, 17), towerList[i].unitName); EditorGUI.LabelField(new Rect(5 + 120, 10 + 60 + i * 49 + 18, 150, 17), " - " + towerList[i].type.ToString()); //~ towerList[i]=(UnitTower)EditorGUI.ObjectField(new Rect(5+120, 10+75+i*49+18, 150, 17), towerList[i], typeof(UnitTower), false); } else { //~ towerList[i]=(UnitTower)EditorGUI.ObjectField(new Rect(5+120, 15+75+i*49, 150, 17), towerList[i], typeof(UnitTower), false); //~ towerIDList.Remove(towerList[i].prefabID); //~ towerList.RemoveAt(i); //~ delete=-1; //~ if(onTowerUpdateE!=null) onTowerUpdateE(); } if (delete != i) { if (GUI.Button(new Rect(window.position.width - 55, 12 + 60 + i * 49, 25, 25), "X")) { delete = i; } } else { GUI.color = Color.red; if (GUI.Button(new Rect(window.position.width - 90, 12 + 60 + i * 49, 60, 25), "Remove")) { if (currentSwapID == i) { currentSwapID = -1; } towerIDList.Remove(towerList[i].prefabID); towerList.RemoveAt(i); delete = -1; if (onTowerUpdateE != null) { onTowerUpdateE(); } } GUI.color = Color.white; } row += 1; } GUI.EndScrollView(); //~ GUI.Label(new Rect(5, window.position.height-55, window.position.width-10, 55), warning); if (GUI.changed) { EditorUtility.SetDirty(prefab); for (int i = 0; i < towerList.Count; i++) { EditorUtility.SetDirty(towerList[i]); } } if (GUI.changed) { //~ EditorUtility.SetDirty(this); Undo.CreateSnapshot(); Undo.RegisterSnapshot(); } Undo.ClearSnapshotTarget(); }
void OnGUI() { if (window == null) { Init(); } #if !UNITY_4_3 Undo.SetSnapshotTarget(this, "ObstacleManagerWindow"); #else Undo.RecordObject(this, "ObstacleManagerWindow"); #endif int currentObstacleCount = obstacleList.Count; EditorGUI.LabelField(new Rect(5, 10, 150, 17), "Add obstacle:"); newObstacle = (Obstacle)EditorGUI.ObjectField(new Rect(100, 10, 150, 17), newObstacle, typeof(Obstacle), false); if (newObstacle != null) { if (!obstacleList.Contains(newObstacle)) { int rand = 0; while (obstacleIDList.Contains(rand)) { rand += 1; } obstacleIDList.Add(rand); newObstacle.prefabID = rand; obstacleList.Add(newObstacle); GUI.changed = true; } newObstacle = null; } //if(obstacleList.Count>0) Texture tex=EditorUtility.GetAssetPreview(obstacleList[0].gameObject); //EditorGUI.ObjectField(new Rect(12+50, 3+60+i*49, 44, 44), tex, typeof(Texture), false); if (obstacleList.Count > 0) { GUI.Box(new Rect(5, 40, 50, 20), "ID"); //GUI.Box(new Rect(5+50-1, 40, 60+1, 20), "Icon"); GUI.Box(new Rect(5 + 50 - 1, 40, 220 + 2, 20), "Info"); GUI.Box(new Rect(5 + 270, 40, window.position.width - 300, 20), ""); } scrollPos = GUI.BeginScrollView(new Rect(5, 60, window.position.width - 12, window.position.height - 50), scrollPos, new Rect(5, 55, window.position.width - 30, 15 + ((obstacleList.Count)) * 110)); int row = 0; for (int i = 0; i < obstacleList.Count; i++) { if (i % 2 == 0) { GUI.color = new Color(.8f, .8f, .8f, 1); } else { GUI.color = Color.white; } GUI.Box(new Rect(5, 60 + i * 109, window.position.width - 30, 110), ""); GUI.color = Color.white; if (currentSwapID == i) { GUI.color = new Color(.9f, .9f, .0f, 1); } if (GUI.Button(new Rect(19, 12 + 60 + i * 109, 30, 30), obstacleList[i].prefabID.ToString())) { if (currentSwapID == i) { currentSwapID = -1; } else if (currentSwapID == -1) { currentSwapID = i; } else { SwapCreep(i); GUI.changed = true; } } if (currentSwapID == i) { GUI.color = Color.white; } if (obstacleList[i] != null) { //unitList[i].icon=(Texture)EditorGUI.ObjectField(new Rect(12+50, 3+60+i*49, 44, 44), unitList[i].icon, typeof(Texture), false); EditorGUI.LabelField(new Rect(5 + 60, 6 + 60 + i * 109, 75, 17), "Name:"); obstacleList[i].obsName = EditorGUI.TextField(new Rect(5 + 120, 6 + 60 + i * 109, 140, 17), obstacleList[i].obsName); //cont=new GUIContent("Type:", "type of unwalkable tile to be applied"); //contL=new GUIContent[unwalkableLabel.Length]; //for(int i=0; i<contL.Length; i++) contL[i]=new GUIContent(unwalkableLabel[i], unwalkableTooltip[i]); //unwalkableType = EditorGUILayout.IntPopup(cont, unwalkableType, contL, intVal); EditorGUI.LabelField(new Rect(5 + 60, 6 + 60 + i * 109 + 20, 120, 17), "Type:"); int obsType = (int)obstacleList[i].obsType; obsType = EditorGUI.IntPopup(new Rect(5 + 120, 6 + 60 + i * 109 + 20, 140, 17), obsType, obstacleTypeLabel, intVal); obstacleList[i].obsType = (_ObsType)obsType; EditorGUI.LabelField(new Rect(5 + 60, 6 + 60 + i * 109 + 40, 120, 17), "Cover:"); int coverType = (int)obstacleList[i].coverType; coverType = EditorGUI.IntPopup(new Rect(5 + 120, 6 + 60 + i * 109 + 40, 140, 17), coverType, coverTypeLabel, intVal); obstacleList[i].coverType = (_CoverType)coverType; EditorGUI.LabelField(new Rect(5 + 60, 6 + 60 + i * 109 + 60, 120, 17), "TileType:"); int tileType = (int)obstacleList[i].tileType; tileType = EditorGUI.IntPopup(new Rect(5 + 120, 6 + 60 + i * 109 + 60, 140, 17), tileType, tileTypeLabel, intVal); obstacleList[i].tileType = (_ObsTileType)tileType; EditorGUI.LabelField(new Rect(5 + 60, 6 + 60 + i * 109 + 80, 75, 17), "Prefab:"); EditorGUI.ObjectField(new Rect(5 + 120, 6 + 60 + i * 109 + 80, 140, 17), obstacleList[i].gameObject, typeof(GameObject), false); //EditorGUI.LabelField(new Rect(5+120, 6+60+i*49+20, 150, 17), "Prefab:"); //EditorGUI.ObjectField(new Rect(5+165, 6+60+i*49+20, 105, 17), obstacleList[i].gameObject, typeof(GameObject), false); } if (delete != i) { if (GUI.Button(new Rect(window.position.width - 55, 12 + 60 + i * 109, 25, 25), "X")) { delete = i; } } else { GUI.color = Color.red; if (GUI.Button(new Rect(window.position.width - 90, 12 + 60 + i * 109, 60, 25), "Remove")) { if (currentSwapID == i) { currentSwapID = -1; } obstacleIDList.Remove(obstacleList[i].prefabID); obstacleList.RemoveAt(i); delete = -1; //~ if(onCreepUpdateE!=null) onCreepUpdateE(); GUI.changed = true; } GUI.color = Color.white; } row += 1; } GUI.EndScrollView(); if (GUI.changed || currentObstacleCount != obstacleList.Count) { EditorUtility.SetDirty(prefab); for (int i = 0; i < obstacleList.Count; i++) { EditorUtility.SetDirty(obstacleList[i]); } } #if UNITY_LE_4_3 if (GUI.changed || currentObstacleCount != obstacleList.Count) { Undo.CreateSnapshot(); Undo.RegisterSnapshot(); } Undo.ClearSnapshotTarget(); #endif }
public override void DrawSceneGUI() { //Undo.RegisterUndo(target, "Move FFD Points"); MegaFFD ffd = (MegaFFD)target; if (ffd.DisplayGizmo) { MegaModifiers context = ffd.GetComponent <MegaModifiers>(); Vector3 size = ffd.lsize; Vector3 osize = ffd.lsize; osize.x = 1.0f / size.x; osize.y = 1.0f / size.y; osize.z = 1.0f / size.z; Matrix4x4 tm1 = Matrix4x4.identity; Quaternion rot = Quaternion.Euler(ffd.gizmoRot); tm1.SetTRS(-(ffd.gizmoPos + ffd.Offset), rot, Vector3.one); if (context != null && context.sourceObj != null) { Handles.matrix = context.sourceObj.transform.localToWorldMatrix * tm1; } else { Handles.matrix = ffd.transform.localToWorldMatrix * tm1; } DrawGizmos(ffd, Handles.matrix); Handles.color = Color.yellow; #if false int pc = ffd.GridSize(); pc = pc * pc * pc; for (int i = 0; i < pc; i++) { Vector3 p = ffd.GetPoint(i); // + ffd.bcenter; //pm = Handles.PositionHandle(p, Quaternion.identity); pm = Handles.FreeMoveHandle(p, Quaternion.identity, ffd.KnotSize * 0.1f, Vector3.zero, Handles.CircleCap); pm -= ffd.bcenter; p = Vector3.Scale(pm, osize); p.x += 0.5f; p.y += 0.5f; p.z += 0.5f; ffd.pt[i] = p; } #endif int gs = ffd.GridSize(); //int i = 0; for (int z = 0; z < gs; z++) { for (int y = 0; y < gs; y++) { for (int x = 0; x < gs; x++) { int index = ffd.GridIndex(x, y, z); //Vector3 p = ffd.GetPoint(i); // + ffd.bcenter; Vector3 p = ffd.GetPoint(index); //ffdi); // + ffd.bcenter; if (handles) { pm = Handles.PositionHandle(p, Quaternion.identity); //pm = PositionHandle(p, Quaternion.identity, handleSize, ffd.gizCol1.a); } else { pm = Handles.FreeMoveHandle(p, Quaternion.identity, ffd.KnotSize * 0.1f, Vector3.zero, Handles.CircleCap); } if (pm != p) { Undo.SetSnapshotTarget(ffd, "FFD Lattice Move"); } Vector3 delta = pm - p; //ffd.SetPoint(x, y, z, pm); pm -= ffd.bcenter; p = Vector3.Scale(pm, osize); p.x += 0.5f; p.y += 0.5f; p.z += 0.5f; ffd.pt[index] = p; if (mirrorX) { int y1 = y - (gs - 1); if (y1 < 0) { y1 = -y1; } if (y != y1) { Vector3 p1 = ffd.GetPoint(ffd.GridIndex(x, y1, z)); // + ffd.bcenter; delta.y = -delta.y; p1 += delta; p1 -= ffd.bcenter; p = Vector3.Scale(p1, osize); p.x += 0.5f; p.y += 0.5f; p.z += 0.5f; ffd.pt[ffd.GridIndex(x, y1, z)] = p; } } if (mirrorY) { int z1 = z - (gs - 1); if (z1 < 0) { z1 = -z1; } if (z != z1) { Vector3 p1 = ffd.GetPoint(ffd.GridIndex(x, y, z1)); // + ffd.bcenter; delta.z = -delta.z; p1 += delta; p1 -= ffd.bcenter; p = Vector3.Scale(p1, osize); p.x += 0.5f; p.y += 0.5f; p.z += 0.5f; ffd.pt[ffd.GridIndex(x, y, z1)] = p; } } if (mirrorZ) { int x1 = x - (gs - 1); if (x1 < 0) { x1 = -x1; } if (x != x1) { Vector3 p1 = ffd.GetPoint(ffd.GridIndex(x1, y, z)); // + ffd.bcenter; delta.x = -delta.x; p1 += delta; p1 -= ffd.bcenter; p = Vector3.Scale(p1, osize); p.x += 0.5f; p.y += 0.5f; p.z += 0.5f; ffd.pt[ffd.GridIndex(x1, y, z)] = p; } } } } } Handles.matrix = Matrix4x4.identity; if (GUI.changed) { //Undo.RegisterCreatedObjectUndo(shape, "plop"); Undo.CreateSnapshot(); Undo.RegisterSnapshot(); } Undo.ClearSnapshotTarget(); } }
public override void OnInspectorGUI() { Undo.SetSnapshotTarget(platform, "BuildPlatform"); GUI.changed = false; //~ EditorGUILayout.Space(); //~ DrawDefaultInspector(); //~ GUILayout.Label("Buildable Type"); //~ EditorGUILayout.BeginHorizontal(); //~ GUILayout.Space(20); //~ int num=platform.buildableType.Length; //~ num=EditorGUILayout.IntField ("Size", num); //~ if(num!=platform.buildableType.Length) UpdateBuildableTypeLength(num); //~ EditorGUILayout.EndHorizontal (); //~ for(int i=0; i<platform.buildableType.Length; i++){ //~ EditorGUILayout.BeginHorizontal(); //~ GUILayout.Space(20); //~ int index=(int)platform.buildableType[i]; //~ index=EditorGUILayout.Popup("Element"+i, index, typeLabel); //~ platform.buildableType[i]=(_TowerType)index; //~ EditorGUILayout.EndHorizontal (); //~ } platform.GizmoShowNodes = GUILayout.Toggle(platform.GizmoShowNodes, "Gizmo Show Nodes"); platform.GizmoShowPath = GUILayout.Toggle(platform.GizmoShowPath, "Gizmo Show Path"); EditorGUILayout.Space(); showTowerList = GUILayout.Toggle(showTowerList, "Show Tower List"); if (showTowerList) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("EnableAll")) { for (int i = 0; i < platform.towerAvaiList.Count; i++) { platform.towerAvaiList[i].enabledInLvl = true; } } if (GUILayout.Button("DisableAll")) { for (int i = 0; i < platform.towerAvaiList.Count; i++) { platform.towerAvaiList[i].enabledInLvl = false; } } EditorGUILayout.EndHorizontal(); for (int i = 0; i < platform.towerAvaiList.Count; i++) { UnitTower tower = towerList[i]; GUILayout.BeginHorizontal(); GUILayout.Box(tower.icon, GUILayout.Width(30), GUILayout.Height(30)); GUILayout.BeginVertical(); GUILayout.Label(tower.name); platform.towerAvaiList[i].enabledInLvl = EditorGUILayout.Toggle("enabled:", platform.towerAvaiList[i].enabledInLvl); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } } EditorGUILayout.Space(); if (GUI.changed) { EditorUtility.SetDirty(platform); Undo.CreateSnapshot(); Undo.RegisterSnapshot(); } Undo.ClearSnapshotTarget(); }
//~ string warning=""; //~ void Test(){ //~ string sourcePath=AssetDatabase.GetAssetPath(resourceList[1].icon); //~ string targetPath=Application.dataPath + "/TDTK/Resources/"; //~ if(AssetDatabase.LoadAssetAtPath(targetPath+resourceList[0].icon.name, typeof(Texture2D))==null){ //~ AssetDatabase.CopyAsset(sourcePath, targetPath); //~ } //~ AssetDatabase.Refresh(); //~ } //~ void ClearWarning(){ //~ warning=""; //~ } //~ void UpdateWarning(){ //~ warning="Please note that you need to save and refresh Resource\nManager in each scene for the new change to take effect."; //~ } void OnGUI() { if (window == null) { Init(); } Undo.SetSnapshotTarget(this, "ResourceEditor"); //~ if(GUI.Button(new Rect(150, 10, 100, 30), "test")){ //~ Test(); //~ } if (GUI.Button(new Rect(window.position.width - 110, 10, 100, 30), "Save")) { //~ warning="Refresh ResourceManager in each scene for the new \nchange to take effect!"; SaveToXML(); } if (GUI.Button(new Rect(10, 10, 100, 30), "New Resource")) { //UpdateWarning(); resourceList.Add(new Resource()); } if (resourceList.Count > 0) { GUI.Box(new Rect(5, 50, 50, 20), "ID"); GUI.Box(new Rect(5 + 50 - 1, 50, 70 + 1, 20), "Texture"); GUI.Box(new Rect(5 + 120 - 1, 50, 150 + 2, 20), "Name"); GUI.Box(new Rect(5 + 270, 50, window.position.width - 280, 20), ""); } int row = 0; for (int i = 0; i < resourceList.Count; i++) { if (i % 2 == 0) { GUI.color = new Color(.8f, .8f, .8f, 1); } else { GUI.color = Color.white; } GUI.Box(new Rect(5, 75 + i * 49, window.position.width - 10, 50), ""); GUI.color = Color.white; GUI.Label(new Rect(22, 15 + 75 + i * 49, 50, 20), i.ToString()); //if(currentSwapID==i) GUI.color=new Color(.9f, .9f, .0f, 1); //if(GUI.Button(new Rect(19, 12+60+i*49, 30, 30), i.ToString())){ // if(currentSwapID==i) currentSwapID=-1; // else if(currentSwapID==-1) currentSwapID=i; // else SwapResource(i); //} //if(currentSwapID==i) GUI.color=Color.white; resourceList[i].icon = (Texture)EditorGUI.ObjectField(new Rect(12 + 50, 3 + 75 + i * 49, 44, 44), resourceList[i].icon, typeof(Texture), false); resourceList[i].name = EditorGUI.TextField(new Rect(5 + 120, 15 + 75 + i * 49, 150, 20), resourceList[i].name); if (delete != i) { if (GUI.Button(new Rect(window.position.width - 35, 12 + 75 + i * 49, 25, 25), "X")) { delete = i; } } else { GUI.color = Color.red; if (GUI.Button(new Rect(window.position.width - 65, 12 + 75 + i * 49, 55, 25), "Delete")) { //if(currentSwapID==i) currentSwapID=-1; resourceList.RemoveAt(i); delete = -1; } GUI.color = Color.white; } row += 1; } //~ GUI.Label(new Rect(5, window.position.height-55, window.position.width-10, 55), warning); if (GUI.changed) { //~ EditorUtility.SetDirty(this); Undo.CreateSnapshot(); Undo.RegisterSnapshot(); } Undo.ClearSnapshotTarget(); }