public GameObject GetObject(object key, string name) { // Get Switch slot SwitchSet slot = GetSlot(key); return(slot.FindObject(objs, o => o.name.EqualsIgnoreCase(name))); }
public object Clone() { SwitchSet e = new SwitchSet(); e.name = this.name; e.visibility = new List <bool>(visibility); e.trans = new List <Transform>(trans); e.pos = new List <Vector3>(pos); #if UNITY_2019_1_OR_NEWER e.data = new List <ICompData>(data); #endif return(e); }
public void AddAction(object key, UnityAction action) { string k = NormalizeKey(key); SwitchSet s = switches.Find(e => e.name.EqualsIgnoreCase(k)); if (s.isValid) { s.action.AddListener(action); } else { Assert.IsTrue(false, $"Key {k} not found"); } }
public T GetComponent <T>(object key) where T : Component { // Get Switch slot SwitchSet slot = GetSlot(key); for (int i = 0; i < slot.visibility.Count; ++i) { if (slot.visibility[i]) { T c = objs[i].GetComponent <T>(); if (c != null) { return(c); } } } return(null); }
private static void ExtractDiff(List <GameObject> roots) { // just set data for the first object var root0 = roots[0]; var diffs = GameObjectDiff.CreateDiff(roots.ToArray()); var tDiffs = GameObjectDiff.FindAll <TransformData>(diffs); // remove TransformData from diffs for (int i = 0; i < diffs.Length; ++i) { diffs[i] = diffs[i].FindAll(d => !(d.GetType() == typeof(TransformData))); } var switcher = root0.GetComponent <Switcher>(); if (switcher != null) { switcher.Clear(); } else { switcher = root0.AddComponent <Switcher>(); Undo.RegisterCreatedObjectUndo(switcher, root0.name); } // Get Visibility Diffs var vDiffs = new List <List <TransformData> >(); for (int i = 0; i < tDiffs.Length; ++i) { vDiffs.Add(new List <TransformData>()); } for (int c = 0; c < tDiffs[0].Count; ++c) { bool diff = false; for (int i = 1; i < tDiffs.Length && !diff; ++i) { diff |= tDiffs[0][c].active != tDiffs[i][c].active; } if (diff) { for (int i = 0; i < tDiffs.Length; ++i) { vDiffs[i].Add(tDiffs[i][c]); } } } switcher.objs = vDiffs[0].ConvertAll(v => v.target.gameObject); // Get Position Diffs var posDiffs = new List <List <TransformData> >(); for (int i = 0; i < tDiffs.Length; ++i) { posDiffs.Add(new List <TransformData>()); } for (int c = 0; c < tDiffs[0].Count; ++c) { if (!tDiffs[0][c].isRoot) { bool diff = false; for (int i = 1; i < tDiffs.Length && !diff; ++i) { diff |= !tDiffs[0][c].TransformEquals(tDiffs[i][c]); } if (diff) { for (int i = 0; i < tDiffs.Length; ++i) { posDiffs[i].Add(tDiffs[i][c]); } } } } for (int i = 0; i < roots.Count; ++i) { var s = new SwitchSet(); s.name = roots[i].name; #if UNITY_2019_1_OR_NEWER s.data = diffs[i]; #endif s.trans = posDiffs[i].ConvertAll(t => t.trans); s.pos = posDiffs[i].ConvertAll(t => t.pos); s.visibility = vDiffs[i].ConvertAll(t => t.enabled); switcher.switches.Add(s); } EditorUtility.SetDirty(switcher); //diffList.serializedProperty.ClearArray(); }