private void DeleteAll(ScriptableObjectParent data) { for (int i = data.subAssets.Count - 1; i >= 0; i--) { Delete(data, i); } }
private void Double(ScriptableObjectParent data, int i) { var d = data.subAssets[i]; var newD = Object.Instantiate(d) as ScriptableObject; AddChild(data, newD); }
private void ShowAll(ScriptableObjectParent data) { for (int i = 0; i < data.subAssets.Count; i++) { data.hides[i] = false; } }
private void MoveDown(ScriptableObjectParent data, int i) { if (i + 1 >= data.subAssets.Count) { return; } Switch(data, i, i + 1); }
private void MoveUp(ScriptableObjectParent data, int i) { if (i - 1 < 0) { return; } Switch(data, i, i - 1); }
void ChangedData(ScriptableObjectParent data) { for (int i = 0; i < data.subAssets.Count; i++) { data.indent[i] = data.GetIndent(data.subAssets[i]); data.warnings[i] = data.GetWarning(data.subAssets[i]); data.warningMessages[i] = data.GetWarningMessage(data.subAssets[i]); } }
private void Delete(ScriptableObjectParent data, int i) { var sub = data.subAssets[i]; data.subAssets.RemoveAt(i); data.hides.RemoveAt(i); DestroyImmediate(sub, true); Undo.RecordObject(data, "DeletAsset"); AssetDatabase.SaveAssets(); ChangedData(data); }
private void Switch(ScriptableObjectParent data, int position, int switchWith) { var other = data.subAssets[switchWith]; var h = data.hides[switchWith]; data.subAssets[switchWith] = data.subAssets[position]; data.hides[switchWith] = data.hides[position]; data.subAssets[position] = other; data.hides[position] = h; ChangedData(data); }
private void PastStack(ScriptableObjectParent data) { if (ScriptableObjectParent.copyStack == null) { return; } var list = ScriptableObjectParent.copyStack; for (int i = 0; i < list.Count; i++) { var newD = Object.Instantiate(list[i]) as ScriptableObject; AddChild(data, newD); } ScriptableObjectParent.copyStack = null; }
protected void AddChild(ScriptableObjectParent data, ScriptableObject newChild) { //string path = GetAssetPath(); //string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + newChild.GetType().ToString() + ".asset"); newChild.name = newChild.GetType().ToString(); AssetDatabase.AddObjectToAsset(newChild, data); data.subAssets.Add(newChild); data.hides.Add(false); data.indent.Add(data.GetIndent(newChild)); data.warnings.Add(data.GetWarning(newChild)); data.warningMessages.Add(data.GetWarningMessage(newChild)); data.hideFlags = HideFlags.None; newChild.hideFlags = HideFlags.None; Undo.RecordObject(newChild, "AddSubAsset"); Undo.RecordObject(data, "AddSubAsset"); AssetDatabase.SaveAssets(); ChangedData(data); }
void DoCreateScriptableObject(ScriptableObjectParent data) { string targetScriptPath; MonoScript targetScript; // Open a File Panel to search for the script targetScriptPath = EditorUtility.OpenFilePanel("Select", data.SubFolder(), "cs"); if (data.SubFolder() == "") { targetScriptPath = EditorUtility.OpenFilePanel("Select", "Assets/", "cs"); } if (targetScriptPath.StartsWith(Application.dataPath)) { targetScriptPath = "Assets" + targetScriptPath.Substring(Application.dataPath.Length); } // Get the target script targetScript = AssetDatabase.LoadAssetAtPath <MonoScript>(targetScriptPath); if (targetScript == null) { return; } // Check if we are a ScriptableObject if (typeof(ScriptableObject).IsAssignableFrom(targetScript.GetClass())) { var newChild = ScriptableObject.CreateInstance(targetScript.GetClass()); AddChild(data, newChild); } else { Debug.LogWarning("Create ScriptableObject Asset failed: Selected Class does not inherit from ScriptableObject"); } }
private void CopyStack(ScriptableObjectParent data) { ScriptableObjectParent.copyStack = new List <ScriptableObject>(data.subAssets); }
private void SortByName(ScriptableObjectParent scriptableObject) { scriptableObject.subAssets.Sort((x, y) => string.Compare(x.name, y.name)); }
private void SortByType(ScriptableObjectParent scriptableObject) { scriptableObject.subAssets.Sort((a, b) => a.GetType().FullName.CompareTo(b.GetType().FullName)); }