/* * private static void OnHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect) * { * Event e = Event.current; * if (e.type == EventType.DragExited) * { * Debug.Log(e.type); * DragAndDrop.visualMode = DragAndDropVisualMode.Copy; * * DragAndDrop.AcceptDrag(); * for (int i = 0; i < DragAndDrop.objectReferences.Length; i++) * { * UnityEngine.Object handleObj = DragAndDrop.objectReferences[i]; * if (handleObj != null) * { * * string path = UnityEditor.AssetDatabase.GetAssetPath(handleObj); * GameObject go = handleObj as GameObject; * * Debug.Log(path); * } * } * * } * * } */ /* * private static void OnSceneGUI(SceneView sceneView) * { * Event e = Event.current; * if (e.type == EventType.DragUpdated || e.type == EventType.DragPerform) * { * DragAndDrop.visualMode = DragAndDropVisualMode.Copy; * if (e.type == EventType.DragPerform) * { * DragAndDrop.AcceptDrag(); * for (int i = 0; i < DragAndDrop.objectReferences.Length; i++) * { * UnityEngine.Object handleObj = DragAndDrop.objectReferences[i]; * if (handleObj != null) * { * * string path = UnityEditor.AssetDatabase.GetAssetPath(handleObj); * Debug.Log(path); * } * } * } * * } * } */ static void OnHierarchyChanged() { STSceneGroup[] groups = FindObjectsOfType <STSceneGroup>(); for (int i = 0; i < groups.Length; ++i) { for (int j = 0; j < groups[i].transform.childCount; ++j) { Transform child = groups[i].transform.GetChild(j); STComponent component = child.GetComponent <STComponent>(); if (component == null) { var targetPrefab = PrefabUtility.GetCorrespondingObjectFromSource(child.gameObject) as GameObject; if (targetPrefab) { string path = AssetDatabase.GetAssetPath(targetPrefab); STSceneEntity entity = AddSTComponentToGroup <STSceneEntity>(groups[i]); entity.transform.position = child.position; entity.transform.localRotation = child.localRotation; entity.transform.localScale = child.localScale; child.SetParent(entity.transform); entity.path = path; child.localPosition = Vector3.zero; child.localRotation = Quaternion.identity; child.localScale = Vector3.one; string assetName = System.IO.Path.GetFileNameWithoutExtension(path); entity.name = typeof(STSceneEntity).Name + "+" + assetName; } } } } }
public void AddSTComponent(STComponent component) { if (attribute.components.Contains(component) == false) { attribute.components.Add(component); } }
public override XmlElement ToXml(XmlNode parent, Dictionary <string, string> attributes = null) { if (attributes == null) { attributes = new Dictionary <string, string>(); } attributes.Add("name", groupName); XmlElement node = base.ToXml(parent, attributes); components.Clear(); for (int i = 0; i < transform.childCount; ++i) { STComponent component = transform.GetChild(i).GetComponent <STComponent>(); if (component) { components.Add(component); } } for (int i = 0; i < components.Count; ++i) { if (components[i] != null) { components[i].ToXml(node); } } return(node); }
public void AddSTComponent(STComponent component) { if (components.Contains(component) == false) { components.Add(component); } }
public override void ParseXml(SecurityElement node) { if (node == null) { return; } if (IsType(node.Tag)) { attribute.name = node.Attribute("name"); attribute.asyn = node.Attribute("asyn").ToBoolEx(); attribute.bounds = node.Attribute("bounds").ToBoundsEx(); attribute.maxCreateCount = node.Attribute("maxCreateCount").ToInt32Ex(); attribute.minCreateCount = node.Attribute("minCreateCount").ToInt32Ex(); attribute.refreshTime = node.Attribute("refreshTime").ToFloatEx(); attribute.destroyTime = node.Attribute("destroyTime").ToFloatEx(); attribute.treeDepth = node.Attribute("treeDepth").ToInt32Ex(); attribute.treeType = (SeparateTreeType)Enum.Parse(typeof(SeparateTreeType), node.Attribute("treeType")); if (node.Children != null) { for (int i = 0; i < node.Children.Count; ++i) { SecurityElement child = node.Children[i] as SecurityElement; GameObject go = new GameObject(child.Tag); go.transform.SetParent(transform); go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; Type component = Type.GetType(child.Tag); if (component == null) { DestroyImmediate(go); continue; } STComponent entity = go.AddComponent(component) as STComponent; if (entity == null) { DestroyImmediate(go); continue; } attribute.components.Add(entity); entity.ParseXml(child); if (entity.IsType(typeof(STSceneEntity).ToString())) { (entity as STSceneEntity).treeType = attribute.treeType; } } } } SetAttribute(); }
protected virtual void OnLoadFinish() { if (transform.parent != null) { STComponent parent = transform.parent.GetComponent <STComponent>(); if (parent) { parent.OnLoadFinish(); } } }
private void AddSTComponent <T>() where T : STComponent { GameObject go = new GameObject(typeof(T).ToString()); go.transform.SetParent(mTarget.transform); go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; STComponent component = go.AddComponent <T>() as STComponent; mTarget.AddSTComponent(component); }
public static STComponent AddSTComponentToGroup(STSceneGroup group, Type type) { GameObject go = new GameObject(type.ToString()); go.transform.SetParent(group.transform); go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; STComponent component = go.AddComponent(type) as STComponent; group.AddSTComponent(component); return(component); }
public override void ParseXml(SecurityElement node) { if (node == null) { return; } base.ParseXml(node); if (IsTypeOrSubClass(node.Tag, typeof(STSceneGroup))) { groupName = node.Attribute("name"); if (node.Children != null) { for (int i = 0; i < node.Children.Count; ++i) { SecurityElement child = node.Children[i] as SecurityElement; GameObject go = new GameObject(child.Tag); go.transform.SetParent(transform); go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; Type component = Type.GetType(child.Tag); if (component == null) { DestroyImmediate(go); continue; } STComponent entity = go.AddComponent(component) as STComponent; if (entity == null) { DestroyImmediate(go); continue; } components.Add(entity); entity.ParseXml(child); } } } }