private void OnEnable() { if (Application.isPlaying) { return; } m_CreatureRoot = GetComponentInChildren <CreatureRoot>(); m_LocationRoot = GetComponentInChildren <LocationRoot>(); m_TeleportRoot = GetComponentInChildren <TeleportRoot>(); m_LeapRoot = GetComponentInChildren <LeapRoot>(); m_TriggerRoot = GetComponentInChildren <TriggerRoot>(); m_TreasureRoot = GetComponentInChildren <TreasureRoot>(); m_MineralRoot = GetComponentInChildren <MineralRoot>(); if (m_LeapRoot == null) { CreateLeapRoot(); } if (m_TriggerRoot == null) { CreateTriggerRoot(); } if (m_TreasureRoot == null) { CreateTreasureRoot(); } if (m_MineralRoot == null) { CreateMineralRoot(); } }
private void CreateTriggerRoot() { GameObject triggerRootObj = new GameObject("TriggerRoot"); triggerRootObj.transform.SetParent(transform); triggerRootObj.transform.localPosition = Vector3.zero; triggerRootObj.transform.localRotation = Quaternion.identity; m_TriggerRoot = triggerRootObj.AddComponent <TriggerRoot>(); }
private void RefreshTriggerRootUI(TriggerRoot root) { if (root == null) { return; } m_ContentCache.Clear(); m_ContentCache.Add(new GUIContent("创建Trigger")); if (root.m_ShowModel) { m_ContentCache.Add(new GUIContent("隐藏模型")); } else { m_ContentCache.Add(new GUIContent("显示模型")); } Vector2 mousePosition = Event.current.mousePosition; GameObject userData = Selection.activeGameObject; int selected = -1; EditorUtility.DisplayCustomMenu(new Rect(mousePosition.x, mousePosition.y, 0, 0), m_ContentCache.ToArray(), selected, delegate(object data, string[] opt, int select) { switch (select) { case 0: //创建Trigger root.CreateTrigger(); break; case 1: root.m_ShowModel = !root.m_ShowModel; break; } }, userData); Event.current.Use(); }
/// <summary> /// 右键响应 /// </summary> /// <param name="instanceID"></param> /// <param name="selectionRect"></param> private void OnHierarchyGUI(int instanceID, Rect selectionRect) { if (Event.current != null && selectionRect.Contains(Event.current.mousePosition) && Event.current.button == 1 && Event.current.type <= EventType.MouseUp) { GameObject selectedGameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject; if (selectedGameObject) { CreatureRoot creatureRoot = selectedGameObject.GetComponent <CreatureRoot>(); if (creatureRoot != null) { RefreshCreatureRootUI(creatureRoot); } Creature creature = selectedGameObject.GetComponent <Creature>(); if (creature != null) { RefreshCreatureUI(creature); } LocationRoot locationRoot = selectedGameObject.GetComponent <LocationRoot>(); if (locationRoot != null) { RefreashLocationRootUI(locationRoot); } Location location = selectedGameObject.GetComponent <Location>(); if (location != null) { RefreshLocationUI(location); } TriggerRoot triggerRoot = selectedGameObject.GetComponent <TriggerRoot>(); if (triggerRoot != null) { RefreshTriggerRootUI(triggerRoot); } Trigger trigger = selectedGameObject.GetComponent <Trigger>(); if (trigger != null) { RefreshTriggerUI(trigger); } TeleportRoot teleportRoot = selectedGameObject.GetComponent <TeleportRoot>(); if (teleportRoot != null) { RefreashTeleportRootUI(teleportRoot); } GamingMapArea mapArea = selectedGameObject.GetComponent <GamingMapArea>(); if (mapArea != null) { RefreshMapAreaUI(mapArea); } GamingMap map = selectedGameObject.GetComponent <GamingMap>(); if (map != null) { RefreshMapUI(map); } Leap leap = selectedGameObject.GetComponent <Leap>(); if (leap != null) { RefreshLeapUI(leap); } } } }
private void OnEnable() { m_Target = target as TriggerRoot; }