示例#1
0
        public static void CollapseAll()
        {
            var type       = typeof(EditorWindow).Assembly.GetType("UnityEditor.SceneHierarchyWindow");
            var methodInfo = type.GetMethod("SetExpandedRecursive");

#if UNITY_2018_2_OR_NEWER
            EditorApplication.ExecuteMenuItem("Window/General/Hierarchy");
#else
            EditorApplication.ExecuteMenuItem("Window/Hierarchy");
#endif
            EditorUtility.DisplayProgressBar("Collapsing All Children", "Please Wait, Monkey Is Collapsing Some Object",
                                             .5f);

            GameObject[] selection = Selection.transforms.Convert(_ => _.gameObject).ToArray();

            if (selection == null || selection.Length == 0)
            {
                selection = TransformExt.GetAllTransformedOrderUpToDown().Convert(_ => _.gameObject).ToArray();
            }

            var window = EditorWindow.focusedWindow;
            if (methodInfo != null)
            {
                foreach (GameObject t in selection)
                {
                    methodInfo.Invoke(window, new object[] { t.GetInstanceID(), false });
                }
            }

            EditorUtility.ClearProgressBar();
        }
示例#2
0
    public override void _PhysicsProcess(float delta)
    {
        deltaTime = delta;
        time     += deltaTime;

        if (time / References.instructionsPerSecond < References.instructionSize && dead == false)
        {
            index = (int)(time * References.instructionsPerSecond);
            if (index < instructions.Length)
            {
                SetInstruction(instructions[index]);
            }
        }
        else
        {
            SetInstruction(Instruction.zero);
            Kill();
        }

        ApplyGravity();
        Thrust();
        Heading();
        transform.position += velocity * delta;
        SetTransform(TransformExt.ToTransform(transform));
    }
示例#3
0
            public static TransformExt FromTransform(Transform transform, Vector3 rotation)
            {
                TransformExt transformExt = new TransformExt();

                transformExt.worldMatrix = Matrix4x4.TransformToMatrix4x4(transform);
                transformExt.position    = Vector3.FromV3(transform.origin);
                transformExt.rotation    = Quaternion.FromEuler(rotation);
                transformExt.scale       = new Vector3(1, 1, 1);
                return(transformExt);
            }
示例#4
0
 public override void _Ready()
 {
     transform          = new TransformExt();
     scale              = Maths.RandomFloat(References.targetMinScale, References.targetMaxScale);
     transform.scale    = new Vector3(scale, scale, scale);
     transform.position = new Vector3(
         Maths.RandomFloat(-References.targetHorizontalRange, References.targetHorizontalRange),
         Maths.RandomFloat(References.targetStartHeight, References.targetEndHeight),
         0);
 }
示例#5
0
 public static Transform ToTransform(TransformExt transformExt)
 {
     if (transformExt.RHStoLHS == true)
     {
         transformExt.posLHS = new Vector3(transformExt.position.x, transformExt.position.y, -transformExt.position.z);
         transformExt.updateTransformMatrix(transformExt.posLHS);
     }
     else
     {
         transformExt.updateTransformMatrix();
     }
     return(Matrix4x4.Matrix4x4ToTransform(transformExt.worldMatrix));
 }
示例#6
0
    public override void _Ready()
    {
        transform          = new TransformExt();
        startPos           = new Vector3(0, References.rocketStartHeight, 0);
        transform.position = startPos;
        transform.rotation = Quaternion.identity;
        transform.scale    = Vector3.one * References.rocketScale;
        exhaust            = (Particles)GetChild(1);
        velocity           = Vector3.zero;
        currentThrust      = 0;
        thrustPercentage   = 0;
        maxExhaustSpeed    = 20;
        maxExhaustTTL      = 1f;

        instructions = new Instruction[References.instructionSize];

        for (int i = 0; i < References.instructionSize; i++)
        {
            instructions[i] = new Instruction();
        }
    }
示例#7
0
 public override void _Process(float delta)
 {
     SetTransform(TransformExt.ToTransform(transform));
 }
示例#8
0
 /// <summary>
 /// 根据路径获取子节点
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public Transform GetChild(string path)
 {
     return(TransformExt.Find(path));
 }
示例#9
0
        public static void SelectInstancesOfPrefab(
            [CommandParameter(Help = "The prefab to find the instances of on the opened scenes",
                              ForceAutoCompleteUsage = true,
                              DefaultValueNameOverride = "Prefab Selected",
                              AutoCompleteMethodName = "PrefabAutoComplete")]
            string prefabName = "")
        {
            GameObject prefab;

            if (prefabName == "")
            {
                prefab = Selection.objects.First(_ => _ is GameObject) as GameObject;
            }
            else
            {
                prefab = AssetDatabase.LoadAssetAtPath <GameObject>(prefabName);
            }

            if (prefab == null)
            {
                Debug.LogWarning("Monkey Error: the prefab was not recognized");
                return;
            }

            EditorUtility.DisplayProgressBar("Finding Prefab Instances...",
                                             "Please Wait while Monkey is looking for the prefab instances!", 0);
            List <Transform> transs = TransformExt.GetAllTransformedOrderUpToDown();
            int i = 0;

            List <GameObject> selectedInstances = new List <GameObject>();

            foreach (Transform transform in transs)
            {
                if (EditorUtility.DisplayCancelableProgressBar("Finding Prefab Instances...",
                                                               "Please Wait while Monkey is looking for the prefab instances!",
                                                               ((float)i / transs.Count) * .5f + .5f))
                {
                    break;
                }

                if (prefab.IsPrefab())
                {
#if UNITY_2018_3_OR_NEWER
                    GameObject prefabRoot = PrefabUtility.GetNearestPrefabInstanceRoot(transform.gameObject);
#else
                    GameObject prefabRoot = PrefabUtility.FindPrefabRoot(transform.gameObject);
#endif
                    // Update the prefab of the game object
                    Object prefabParent = prefabRoot ? GetPrefabParentPlatformIndependant(prefabRoot) : null;

                    if (prefabParent == prefab && !selectedInstances.Contains(prefabRoot))
                    {
                        selectedInstances.Add(prefabRoot);
                    }
                }
                else
                {
                    //then it's a model
                    MeshFilter filter = transform.gameObject.GetComponent <MeshFilter>();
                    if (filter)
                    {
                        MeshFilter[] filters = prefab.GetComponentsInChildren <MeshFilter>();
                        if (filters.Any(_ => _.sharedMesh == filter.sharedMesh))
                        {
                            selectedInstances.Add(filter.gameObject);
                        }
                    }
                }

                i++;
            }

            Selection.objects = selectedInstances.Convert(_ => _ as Object).ToArray();
            EditorUtility.ClearProgressBar();
        }