Exemplo n.º 1
0
        public void OnUpdate(IBulletController controller)
        {
            if (axis == Vector3.zero)
            {
                BulletStormLogger.LogErrorOnce($"{controller}: In Around axis module, axis can't be zero!");
                return;
            }

            Vector3 axisInWorld;

            switch (space)
            {
            case Space.World:
                axisInWorld = axis;
                break;

            case Space.Self:
                axisInWorld = controller.Rotation * axis;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            var angle = anglePerSecond * Time.deltaTime;

            controller.ChangeParam(param =>
            {
                param.rotation = Quaternion.AngleAxis(angle, axisInWorld) * param.rotation;
                return(param);
            });
        }
Exemplo n.º 2
0
        public void Build()
        {
            var port = GetInputPort(nameof(shape));

            if (!port.IsConnected)
            {
                BulletStormLogger.LogWarning("The output node has no input value, check if you forget to connect it.");
                return;
            }

            if (!(port.Connection.node is ShapeNode lastNode) || !lastNode)
            {
                BulletStormLogger.LogError($"Unknown output type {port.Connection.node.GetType().FullName}, expected {typeof(ShapeNode).FullName}");
                return;
            }

            lastNode.RecursiveGenerate();
            if (!(graph is ShapeGraph shapeGraph) || !shapeGraph)
            {
                BulletStormLogger.LogError($"Unknown graph type {graph.GetType().FullName}, this node is output node for {typeof(ShapeAsset).FullName}");
                return;
            }

            shapeGraph.shape = lastNode.GetShape();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets path of bullet storm folder.
        /// </summary>
        /// <returns></returns>
        public static string GetBasePath()
        {
            if (!(_basePath is null) && _basePath.StartsWith("Assets/"))
            {
                return(_basePath);
            }

            var assets = AssetDatabase.FindAssets("BulletStorm t:asmdef");

            Assert.IsNotNull(assets);

            var selected = assets.ToList().ConvertAll(AssetDatabase.GUIDToAssetPath)
                           .Where(path => path.EndsWith("/BulletStorm.asmdef")).ToList();

            if (selected.Count == 1)
            {
                _basePath = selected[0].Substring(0, selected[0].LastIndexOf('/'));
                return(_basePath);
            }

            BulletStormLogger.LogError("Can't locate bullet storm assembly, find " + (selected.Count > 0
                ? selected.Count + " items:\n" + selected.Aggregate((current, next) => current + "\n" + next)
                : "0 item."));
            _basePath = "Assets/BulletStorm";
            return(_basePath);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Compile the storm.
        /// </summary>
        /// <returns>True if successes.</returns>
        public bool Compile()
        {
            var scopes = new Stack <int>();

            try
            {
                var index = 0;
                foreach (var stormEvent in events)
                {
                    stormEvent.Compile(this, scopes, index++);
                }

                if (scopes.Count == 0)
                {
                    Compiled = true;
                }
                else
                {
                    BulletStormLogger.LogError(""); // TODO: Write error info.
                    Compiled = false;
                }
            }
            catch (StormCompileException e)
            {
                BulletStormLogger.LogException(e);
                Compiled = false;
            }

            return(Compiled);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Call this on every update.
        /// </summary>
        /// <param name="bullet"></param>
        public void OnUpdate(IBulletController bullet)
        {
            if (!target.Check())
            {
                BulletStormLogger.LogWarningOnce($"Can not find {target}");
                return;
            }

            var targetPosition = target.AsTransform.position;
            var rate           = tracingRate * Time.deltaTime;
            var enableCurve    = enableRateCurve;
            var curve          = tracingRateCurve;

            bullet.ChangeParam(param =>
            {
                var direction    = param.rotation * Vector3.forward;
                var aimDirection = targetPosition - param.position;
                var axis         = Vector3.Cross(direction, aimDirection);
                var dAngle       = enableCurve ? curve.Evaluate(Vector3.Angle(direction, aimDirection)) * rate : rate;
                if (dAngle < 0)
                {
                    dAngle = 0;
                }
                param.rotation = Quaternion.AngleAxis(dAngle, axis) * param.rotation;
                return(param);
            });
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="shapeNode"></param>
        /// <param name="inputPortName"></param>
        /// <returns>Default if failed.</returns>
        public static ShapeNode GetInputShapeNode(this ShapeNode shapeNode, string inputPortName)
        {
            var port = shapeNode.GetInputPort(inputPortName);

            if (port is null)
            {
                BulletStormLogger.LogError($"Node {shapeNode}: port 'inputShape' not found.");
                return(default);
Exemplo n.º 7
0
 private bool CheckBullet()
 {
     if (bullet)
     {
         return(true);
     }
     BulletStormLogger.LogError($"{this}: Bullet is empty!");
     return(false);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a prefab and save to assets.
        /// </summary>
        /// <param name="name">Prefab name</param>
        /// <param name="path">Asset folder path</param>
        /// <typeparam name="T">Script type</typeparam>
        private static void CreatePrefab <T>(string name, string path) where T : MonoBehaviour
        {
            var go = EditorUtility.CreateGameObjectWithHideFlags(
                name, HideFlags.DontSaveInEditor & HideFlags.HideInHierarchy, typeof(T));
            var uniquePath = AssetDatabase.GenerateUniqueAssetPath(path + "/" + name + ".prefab");

            PrefabUtility.SaveAsPrefabAsset(go, uniquePath);
            Object.DestroyImmediate(go);
            BulletStormLogger.Log("Created prefab '" + name + "'.\n" + path + "/" + name);
        }
Exemplo n.º 9
0
 public void Build()
 {
     if (CheckOutputNode())
     {
         outputNode.Build();
     }
     else
     {
         BulletStormLogger.LogError("Output node not found.");
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Creates an asset of given shape.
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="assetPath"></param>
        public static void CreateAsset(Shape shape, string assetPath)
        {
#if UNITY_EDITOR
            var shapeAsset = CreateInstance <ShapeAsset>();
            shapeAsset.shape = shape;
            AssetDatabase.CreateAsset(shapeAsset, assetPath);
#else
            BulletStormLogger.LogError("Can't create asset in game.");
            return;
#endif
        }
Exemplo n.º 11
0
        public override void OnCreate()
        {
            base.OnCreate();

            quaternion = target as Quaternion;
            if (quaternion is null || !quaternion)
            {
                BulletStormLogger.LogError("Failed to initiate editor.");
                return;
            }

            value     = quaternion.GetOutputPort(nameof(value));
            type      = serializedObject.FindProperty(nameof(type));
            setUpward = serializedObject.FindProperty(nameof(setUpward));
            vector0   = serializedObject.FindProperty(nameof(vector0));
            vector1   = serializedObject.FindProperty(nameof(vector1));
        }
Exemplo n.º 12
0
        protected override IEnumerator StartEmitCoroutine()
        {
            emitCount = 0;
            foreach (var emission in emissions)
            {
                var overriden = emission.OverridenShape;

                var repeatTimes = emission.repeat ? emission.repeatTimes : 1;

                if (emission.newReferenceSystem)
                {
                    SetReferenceSystem(bullet, Emitter.rotation);
                }

                for (var i = 0; i < repeatTimes; i++)
                {
                    if (overriden is null)
                    {
                        BulletStormLogger.LogWarning($"{this}: in emission element {emitCount}, shape not set");
                    }
                    else if (!emission.oneByOne)
                    {
                        Emit(overriden, bullet);
                    }
                    else
                    {
                        for (var j = 0; j < overriden.Count; j++)
                        {
                            if (j != 0)
                            {
                                yield return(new WaitForSeconds(emission.interval));
                            }
                            Emit(overriden[j], bullet);
                        }
                    }

                    onEmit.Invoke();
                    emitCount++;
                    yield return(new WaitForSeconds(emission.wait));
                }
            }
        }
Exemplo n.º 13
0
        public override void OnDropObjects(Object[] objects)
        {
            var  pos    = window.WindowToGridPosition(Event.current.mousePosition) - new Vector2(15, 15);
            var  cnt    = 0;
            var  offset = new Vector2(10, 10);
            var  add    = false;
            Node node   = null;

            foreach (var @object in objects)
            {
                switch (@object)
                {
                case ShapeAsset asset:
                {
                    node = CreateNode(typeof(ShapeReference), pos + offset * cnt++);
                    window.SelectNode(node, add);
                    add = true;
                    if (node is ShapeReference shapeReference)
                    {
                        shapeReference.shapeAsset = asset;
                    }
                    else
                    {
                        BulletStormLogger.LogError("An unexpected errored occured when creating node.");
                    }
                    break;
                }

                default:
                    BulletStormLogger.Log($"{@object} can't drop into shape graph");
                    break;
                }

                Util.System.SendMessage(node, "OnValidate");
            }
        }