void Start()
 {
     _events      = HierarchyUtils.GetComponentsInDirectChildren <Event>(transform, false);
     _eventId     = 0;
     _activeEvent = _events[_eventId];
     StartEvent();
 }
Ejemplo n.º 2
0
    void OnGUI()
    {
        DrawFilterFolders();

        if (GUILayout.Button("Search"))
        {
            if (string.IsNullOrEmpty(_scriptName))
            {
                EditorUtility.DisplayDialog("请输入一个有效的脚本名称", "提示", "确定");
                return;
            }

            Type type = _currentType;

            if (_currentType.Equals(typeof(MonoBehaviour)))
            {
                System.Reflection.Assembly assembly = HierarchyUtils.GetAssembly();
                type = assembly.GetType(_scriptName);

                if (type == null)
                {
                    EditorUtility.DisplayDialog("没找到该类:" + _scriptName, "提示", "确定");
                    return;
                }
            }

            List <string> prefabNames = FindScriptInPrefab(type);
            ShowPrefabNameEditor.ShowWindow(prefabNames);
        }
    }
Ejemplo n.º 3
0
        private void OnCommandAddedToScript(Script script, Command parentCommand, Command command)
        {
            var addedNode         = HierarchyUtils.OnCommandAddedToScript(m_Nodes, script, parentCommand, command);
            var postRefreshAction = (addedNode.Parent.Children.Count == 1) ? () => treeListView.Expand(addedNode.Parent) : default(Action);

            RefreshTreeListViewAsync(postRefreshAction);
        }
Ejemplo n.º 4
0
        public TestFixtureWindow(ITestRunner TestRunner, ITestFixtureManager TestFixtureManager,
                                 IHierarchyNodeStringConverter HierarchyNodeStringConverter, ICommandFactory CommandFactory)
        {
            this.TestRunner                   = TestRunner;
            this.TestFixtureManager           = TestFixtureManager;
            this.HierarchyNodeStringConverter = HierarchyNodeStringConverter;
            this.CommandFactory               = CommandFactory;

            InitializeComponent();
            AutoScaleMode = AutoScaleMode.Dpi;

            treeListView.Font = Fonts.Default;

            TestRunner.TestRunEnd += OnScriptsFinishedRunning;
            TestRunner.TestData.CommandRunningCallback += OnCommandRunning;

            treeListView.FormatCell += UpdateFontsTreeListView;
            HierarchyUtils.CreateColumns(treeListView, HierarchyNodeStringConverter);

            // subscribing for both treeListView and contextMenuStrip creation, since it's not clear which will be created first
            treeListView.HandleCreated     += AddNewCommandsToCreateMenu;
            contextMenuStrip.HandleCreated += AddNewCommandsToCreateMenu;
            CommandFactory.NewUserCommands += AddNewCommandsToCreateMenu;

            UpdateHierarchy();
        }
Ejemplo n.º 5
0
        private void AddNewCommandsToCreateMenu()
        {
            if (CommandFactory == null || contextMenuStrip == null || treeListView == null || ScriptManager == null)
            {
                Logger.Log(LogType.Error, "HierarchyWindow.AddNewCommandsToCreateMenu() was called to early. Creating commands will not be possible. Please report a bug.",
                           "CommandFactory " + (CommandFactory == null) + ", contextMenuStrip " + (contextMenuStrip == null) +
                           ", treeListView " + (treeListView == null) + ", TestFixture " + (ScriptManager == null));
                return;
            }

            HierarchyUtils.OnNewUserCommandsAppeared(CommandFactory, contextMenuStrip, 8,
                                                     treeListView, ScriptManager as BaseScriptManager);
        }
    public static void DestroyChilds(this Transform t)
    {
        var childs = new List <Transform>();

        foreach (Transform child in t)
        {
            childs.Add(child);
        }
        foreach (var child in childs)
        {
            HierarchyUtils.SafeDestroy(child.gameObject);
        }
    }
Ejemplo n.º 7
0
        // TODO: Implement this
        protected override void OnUpdate()
        {
            var parents = GetComponentDataFromEntity <Parent>(true);

            Entities.ForEach((Entity entity, ref FillAmount c0, in MaterialPropertyIndex c1, in SpriteData c2) => {
                var current = c0.Amount;
                current     = ((float)math.cos(Time.ElapsedTime) + 1) / 2;
                c0.Amount   = current;

                var canvasRoot     = HierarchyUtils.GetRoot(entity, parents);
                var properties     = EntityManager.GetComponentData <MaterialPropertyBatch>(canvasRoot);
                var associatedProp = properties.Value[c1.Value];

                associatedProp.SetInt(ShaderIDConstants.FillType, c0.FillTypeAsInt());
                associatedProp.SetFloat(ShaderIDConstants.Fill, current);
            }).WithoutBurst().Run();
Ejemplo n.º 8
0
            public void Execute(Entity msgEntity, DynamicBuffer <CloseTarget> b0)
            {
                var buffer = b0.AsNativeArray();

                for (int i = 0; i < buffer.Length; i++)
                {
                    var targetEntity = buffer[i].Value;

                    // Check the metadata of the entity and update its state
                    var root         = HierarchyUtils.GetRoot(targetEntity, Parents);
                    var activeStates = Metadata[root];

                    if (activeStates.Value.TryGetValue(targetEntity, out bool isActive))
                    {
                        isActive = !isActive;
                        activeStates.Value[targetEntity] = isActive;
                    }

                    if (isActive && Disabled.HasComponent(targetEntity) &&
                        (ShowButtons.HasComponent(msgEntity) || ToggleButtons.HasComponent(msgEntity)))
                    {
                        CmdBuffer.RemoveComponent <Disabled>(targetEntity);
                        CmdBuffer.AddComponent <EnableRenderingTag>(targetEntity);

                        if (LocalVertices.HasComponent(targetEntity))
                        {
                            CmdBuffer.AddComponent <UpdateVertexColorTag>(targetEntity);
                        }
                        RecurseChildrenAndEnable(targetEntity, ref activeStates.Value);
                    }

                    if (!isActive && (CloseButtons.HasComponent(msgEntity) || ToggleButtons.HasComponent(msgEntity)))
                    {
                        CmdBuffer.AddComponent <Disabled>(targetEntity);

                        if (LocalVertices.HasComponent(targetEntity))
                        {
                            CmdBuffer.AddComponent <UpdateVertexColorTag>(targetEntity);
                        }

                        RecurseChildrenAndDisabled(targetEntity);
                    }
                }
            }
Ejemplo n.º 9
0
        private void InitializeBlendShapeItems(Transform target)
        {
            if (target == null)
            {
                return;
            }

            var renderers = HierarchyUtils
                            .GetAllChildrenRecurse(target)
                            .Select(t =>
            {
                try
                {
                    return(t.GetComponent <SkinnedMeshRenderer>());
                }
                catch (Exception)
                {
                    return(null);
                }
            })
                            .Where(r => r != null)
                            .ToArray();

            var blendShapes = new List <BlendShapeStoreItem>();

            for (int i = 0; i < renderers.Length; i++)
            {
                var renderer = renderers[i];
                var mesh     = renderer.sharedMesh;
                for (int j = 0; j < mesh.blendShapeCount; j++)
                {
                    string name = mesh.GetBlendShapeName(j);
                    blendShapes.Add(new BlendShapeStoreItem()
                    {
                        renderer = renderer,
                        name     = name,
                        index    = mesh.GetBlendShapeIndex(name),
                    });
                }
            }

            _blendShapeItems = blendShapes.ToArray();
        }
Ejemplo n.º 10
0
        private void AddNewCommandsToCreateMenu()
        {
            if (CommandFactory == null || contextMenuStrip == null || treeListView == null)
            {
                Logger.Log(LogType.Error, "TestFixtureWindow.AddNewCommandsToCreateMenu() was called to early. Creating commands will not be possible. Please report a bug.",
                           "CommandFactory " + (CommandFactory == null) + ", contextMenuStrip " + (contextMenuStrip == null) +
                           ", treeListView " + (treeListView == null) + ", TestFixture " + (m_TestFixture == null));
                return;
            }

            if (m_TestFixture == null)
            {
                // Sometimes this will be called with m_TestFixture not assigned yet. It depends how fast ui elements are created.
                // So it is easier to just early return here. New user commands will be added upon other callback
                return;
            }

            HierarchyUtils.OnNewUserCommandsAppeared(CommandFactory, contextMenuStrip, 5,
                                                     treeListView, m_TestFixture);
        }
        protected override void OnUpdate()
        {
            var ltws    = GetComponentDataFromEntity <LocalToWorld>(true);
            var parents = GetComponentDataFromEntity <Parent>(true);

            Entities.ForEach((Entity e, ref PingPongPositions c0, ref Translation c2, ref LocalToParent c3,
                              in MaterialPropertyIndex c1) => {
                var x = c2.Value.x;

                if (math.distance(x, c0.Target) <= 0.2f)
                {
                    c0.Target = c0.AdjustedWidth;
                }

                if (math.distance(x, c0.Target) <= 0.2f)
                {
                    c0.Target = -c0.AdjustedWidth;
                }

                x = math.lerp(x, c0.Target, Time.DeltaTime);

                var matrix     = float4x4.TRS(new float3(x, 0, 0), quaternion.identity, new float3(1));
                var localSpace = new LocalToParent {
                    Value = matrix
                };

                var root     = HierarchyUtils.GetRoot(e, parents);
                var batch    = EntityManager.GetComponentData <MaterialPropertyBatch>(root);
                var property = batch.Value[c1.Value];
                property.SetVector(ShaderIDConstants.Translation, new float4(localSpace.Position, 0));

                c3 = localSpace;
                c2 = new Translation {
                    Value = localSpace.Position
                };
            }).WithoutBurst().Run();
        }
Ejemplo n.º 12
0
        public HierarchyWindow(IScriptManager ScriptManager, ITestRunner TestRunner, IAssetManager AssetManager,
                               IHierarchyNodeStringConverter HierarchyNodeStringConverter, ICommandFactory CommandFactory)
        {
            this.ScriptManager = ScriptManager;
            this.TestRunner    = TestRunner;
            this.AssetManager  = AssetManager;
            this.HierarchyNodeStringConverter = HierarchyNodeStringConverter;
            this.CommandFactory = CommandFactory;

            InitializeComponent();
            AutoScaleMode = AutoScaleMode.Dpi;

            treeListView.Font = Fonts.Default;

            ScriptManager.CommandAddedToScript     += OnCommandAddedToScript;
            ScriptManager.CommandRemovedFromScript += OnCommandRemovedFromScript;
            ScriptManager.CommandModifiedOnScript  += OnCommandModifiedOnScript;
            ScriptManager.CommandInsertedInScript  += OnCommandInsertedInScript;

            ScriptManager.ScriptAdded              += OnScriptLoaded;
            ScriptManager.ScriptModified           += OnScriptModified;
            ScriptManager.ScriptRemoved            += OnScriptRemoved;
            ScriptManager.ScriptPositioningChanged += OnScriptPositioningChanged;

            TestRunner.TestRunEnd += OnScriptsFinishedRunning;
            TestRunner.TestData.CommandRunningCallback += OnCommandRunning;

            // subscribing for both treeListView and contextMenuStrip creation, since it's not clear which will be created first
            treeListView.HandleCreated     += AddNewCommandsToCreateMenu;
            contextMenuStrip.HandleCreated += AddNewCommandsToCreateMenu;
            CommandFactory.NewUserCommands += AddNewCommandsToCreateMenu;

            treeListView.FormatCell += UpdateFontsTreeListView;
            HierarchyUtils.CreateColumns(treeListView, HierarchyNodeStringConverter);

            treeListView.HandleCreated += UpdateHierarchy;
        }
Ejemplo n.º 13
0
    private void LoadLevel(Level prefab)
    {
        if (_currentLevel != null)
        {
            var closure = _currentLevel;
            closure.DOMove(-levelSpawnHeight * Vector3.up * closure.radius, levelChangeDuration).OnComplete(() =>
            {
                HierarchyUtils.SafeDestroy(closure.gameObject, 0.1f);
            });
        }

        _currentLevel = Instantiate(
            prefab,
            levelSpawnHeight * Vector3.up * prefab.radius,
            Quaternion.identity,
            transform);
        _currentLevel.OnDestruct += HandleLevelSuccess;
        _currentLevel.DOMove(Vector3.zero, levelChangeDuration);

        var barrels = _currentLevel.GetComponentsInChildren <Barrel>(true);

        foreach (var barrel in barrels)
        {
            barrel.explosive.OnExplode += () =>
            {
                var pos       = barrel.transform.position;
                var explosion = explosions.Lock();
                explosion.Explode(pos);
                soundManager.PlayExplosion(pos);
            };
        }

        player.SetShootVelocity(_currentLevel.cannonBallStartVelocity);

        player.DORadius(prefab.radius, levelChangeDuration);
    }
Ejemplo n.º 14
0
 private void OnCommandModifiedOnScript(Script script, Command oldCommand, Command newCommand)
 {
     HierarchyUtils.OnCommandModifiedOnScript(m_Nodes, script, oldCommand, newCommand);
     RefreshTreeListViewAsync();
 }
Ejemplo n.º 15
0
        // Will not work with multi dragging
        private void OnCommandInsertedInScript(Script script, Command parentCommand, Command command, int pos)
        {
            var node = HierarchyUtils.OnCommandInsertedInScript(m_Nodes, script, parentCommand, command, pos);

            RefreshTreeListViewAsync(() => treeListView.SelectedObject = node);
        }
Ejemplo n.º 16
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var colors         = chunk.GetNativeArray(AppliedColorType);
                var vertexBuffers  = chunk.GetBufferAccessor(LocalVertexType);
                var entities       = chunk.GetNativeArray(EntityType);
                var isDisabled     = chunk.Has(DisabledType);
                var isNewlyEnabled = chunk.Has(EnableRenderingType);

                // If newly disabled
                if (isDisabled && !isNewlyEnabled)
                {
                    for (int i = 0; i < chunk.Count; i++)
                    {
                        var entity   = entities[i];
                        var vertices = vertexBuffers[i].AsNativeArray();
                        var color    = colors[i].Value.ToNormalizedFloat4();

                        for (int m = 0; m < vertices.Length; m++)
                        {
                            var cpy = vertices[m];
                            cpy.Color     = default;
                            cpy.Position += Offset;
                            vertices[m]   = cpy;
                        }

                        var root = HierarchyUtils.GetRoot(entity, Parents);
                        CmdBuffer.AddComponent <DisableRenderingTag>(chunkIndex, root);
                    }
                }

                // If this has been rendered to begin with
                if (!isDisabled && !isNewlyEnabled)
                {
                    for (int i = 0; i < chunk.Count; i++)
                    {
                        var entity   = entities[i];
                        var vertices = vertexBuffers[i].AsNativeArray();
                        var color    = colors[i].Value.ToNormalizedFloat4();

                        for (int m = 0; m < vertices.Length; m++)
                        {
                            var cpy = vertices[m];
                            cpy.Color   = color;
                            vertices[m] = cpy;
                        }

                        var root = HierarchyUtils.GetRoot(entity, Parents);
                        CmdBuffer.AddComponent <UpdateVertexColorTag>(chunkIndex, root);
                    }
                }

                // If the chunk is newly renabled
                if (!isDisabled && isNewlyEnabled)
                {
                    for (int i = 0; i < chunk.Count; i++)
                    {
                        var entity   = entities[i];
                        var vertices = vertexBuffers[i].AsNativeArray();
                        var color    = colors[i].Value.ToNormalizedFloat4();

                        for (int m = 0; m < vertices.Length; m++)
                        {
                            var cpy = vertices[m];
                            cpy.Color     = color;
                            cpy.Position -= Offset;
                            vertices[m]   = cpy;
                        }

                        var root = HierarchyUtils.GetRoot(entity, Parents);
                        CmdBuffer.AddComponent <UpdateVertexColorTag>(chunkIndex, root);
                    }
                }
            }
Ejemplo n.º 17
0
 private void OnCommandRemovedFromScript(Script script, Command parentCommand, int commandIndex)
 {
     HierarchyUtils.OnCommandRemovedFromScript(m_Nodes, script, parentCommand, commandIndex);
     RefreshTreeListViewAsync();
 }