コード例 #1
0
        public override void OnEnter()
        {
            result.Reset();

            //convert FsmString[] to string[]
            string[] strArr = new string[searchBy.Length];

            for (int i = 0; i < searchBy.Length; i++)
            {
                strArr[i] = searchBy[i].Value;
            }

            List <string> matchingValues = GDEHelpers.FindAllMatching(dataType, searchType, strArr, "", false);

            if (matchingValues.Count == 0)
            {
                Fsm.Event(noneFoundEvent);
            }
            else
            {
                result.SetArrayContents(matchingValues);
            }

            Finish();
        }
コード例 #2
0
        public override void Reset()
        {
            base.Reset();

            if (StoreResult != null)
            {
                StoreResult.Reset();
            }
        }
コード例 #3
0
        public override void Reset()
        {
            base.Reset();

            if (Variable != null)
            {
                Variable.Reset();
            }
        }
コード例 #4
0
        public override void OnEnter()
        {
            result.Reset();

            foreach (var fieldName in fieldNames)
            {
                result.Add(GDEHelpers.GetFieldValue(itemName.Value, fieldName.Value));
            }

            if (result.Length == 0)
            {
                Fsm.Event(noneFoundEvent);
            }

            Finish();
        }
コード例 #5
0
        public override void OnEnter()
        {
            result.Reset();

            List <string> tmpValues      = GDEHelpers.ListAllBy(GDEDataType.Item, searchInSchema.Value);
            List <string> matchingValues = new List <string>();

            foreach (var tmp in tmpValues)
            {
                if (string.IsNullOrEmpty(itemNameContains.Value) && !itemNameContains.IsNone && !tmp.Contains(itemNameContains.Value))
                {
                    continue;
                }

                List <string> fieldNames = string.IsNullOrEmpty(searchInField.Value) || searchInField.IsNone ? null : new List <string> {
                    searchInField.Value
                };
                List <object> fieldValues = GDEHelpers.GetFieldValues(tmp, fieldNames);

                foreach (var fieldValue in fieldValues)
                {
                    value.UpdateValue();
                    if (fieldValue.GetType() != value.GetType())
                    {
                        UnityEngine.Debug.LogError("Given value type doesn't match result type!");
                    }
                    if (fieldValue != value.GetValue())
                    {
                        continue;
                    }

                    matchingValues.Add(tmp);
                    break;
                }
            }

            if (matchingValues.Count == 0)
            {
                Fsm.Event(noneFoundEvent);
            }
            else
            {
                result.SetArrayContents(matchingValues);
            }

            Finish();
        }
コード例 #6
0
ファイル: ArrayClear.cs プロジェクト: smdx24/CPI-Source-Code
        public override void OnEnter()
        {
            int length = array.Length;

            array.Reset();
            array.Resize(length);
            if (!resetValue.IsNone)
            {
                resetValue.UpdateValue();
                object value = resetValue.GetValue();
                for (int i = 0; i < length; i++)
                {
                    array.Set(i, value);
                }
            }
            Finish();
        }
コード例 #7
0
        public override void OnEnter()
        {
            int count = array.Length;

            array.Reset();
            array.Resize(count);

            if (!resetValue.IsNone)
            {
                object _val = resetValue.GetValue();
                for (int i = 0; i < count; i++)
                {
                    array.Set(i, _val);
                }
            }
            Finish();
        }
コード例 #8
0
        public override void OnEnter()
        {
            result.Reset();

            List <string> tmpValues      = GDEHelpers.ListAllBy(GDEDataType.Item, searchInSchema.Value);
            List <string> matchingValues = new List <string>();

            foreach (var tmp in tmpValues)
            {
                if (string.IsNullOrEmpty(itemNameContains.Value) && !itemNameContains.IsNone && !tmp.Contains(itemNameContains.Value))
                {
                    continue;
                }

                List <string> fieldNames = string.IsNullOrEmpty(searchInField.Value) || searchInField.IsNone ? null : new List <string> {
                    searchInField.Value
                };
                List <object> fieldValues = GDEHelpers.GetFieldValues(tmp, fieldNames);

                foreach (var fieldValue in fieldValues)
                {
                    if (fieldValue.ToString() == _value.Value)
                    {
                        matchingValues.Add(tmp);
                        break;
                    }
                }
            }

            if (matchingValues.Count == 0)
            {
                Fsm.Event(noneFoundEvent);
            }
            else
            {
                result.SetArrayContents(matchingValues);
            }

            Finish();
        }
コード例 #9
0
    public static bool ApplyValueToFsmVar(Fsm fromFsm, FsmVar fsmVar, object value)
    {
        if (fromFsm == null)
        {
            return(false);
        }
        if (fsmVar == null)
        {
            return(false);
        }


        if (value == null)
        {
            if (fsmVar.Type == VariableType.Bool)
            {
                FsmBool _target = fromFsm.Variables.GetFsmBool(fsmVar.variableName);
                _target.Value = false;
            }
            else if (fsmVar.Type == VariableType.Color)
            {
                FsmColor _target = fromFsm.Variables.GetFsmColor(fsmVar.variableName);
                _target.Value = Color.black;
            }
            else if (fsmVar.Type == VariableType.Int)
            {
                FsmInt _target = fromFsm.Variables.GetFsmInt(fsmVar.variableName);
                _target.Value = 0;
            }
            else if (fsmVar.Type == VariableType.Float)
            {
                FsmFloat _target = fromFsm.Variables.GetFsmFloat(fsmVar.variableName);
                _target.Value = 0f;
            }
            else if (fsmVar.Type == VariableType.GameObject)
            {
                FsmGameObject _target = fromFsm.Variables.GetFsmGameObject(fsmVar.variableName);
                _target.Value = null;
            }
            else if (fsmVar.Type == VariableType.Material)
            {
                FsmMaterial _target = fromFsm.Variables.GetFsmMaterial(fsmVar.variableName);
                _target.Value = null;
            }
            else if (fsmVar.Type == VariableType.Object)
            {
                FsmObject _target = fromFsm.Variables.GetFsmObject(fsmVar.variableName);
                _target.Value = null;
            }
            else if (fsmVar.Type == VariableType.Quaternion)
            {
                FsmQuaternion _target = fromFsm.Variables.GetFsmQuaternion(fsmVar.variableName);
                _target.Value = Quaternion.identity;
            }
            else if (fsmVar.Type == VariableType.Rect)
            {
                FsmRect _target = fromFsm.Variables.GetFsmRect(fsmVar.variableName);
                _target.Value = new Rect(0, 0, 0, 0);
            }
            else if (fsmVar.Type == VariableType.String)
            {
                FsmString _target = fromFsm.Variables.GetFsmString(fsmVar.variableName);
                _target.Value = "";
            }
            else if (fsmVar.Type == VariableType.String)
            {
                FsmTexture _target = fromFsm.Variables.GetFsmTexture(fsmVar.variableName);
                _target.Value = null;
            }
            else if (fsmVar.Type == VariableType.Vector2)
            {
                FsmVector2 _target = fromFsm.Variables.GetFsmVector2(fsmVar.variableName);
                _target.Value = Vector2.zero;
            }
            else if (fsmVar.Type == VariableType.Vector3)
            {
                FsmVector3 _target = fromFsm.Variables.GetFsmVector3(fsmVar.variableName);
                _target.Value = Vector3.zero;
            }
                        #if PLAYMAKER_1_8
            else if (fsmVar.Type == VariableType.Enum)
            {
                FsmEnum _target = fromFsm.Variables.GetFsmEnum(fsmVar.variableName);
                _target.ResetValue();
            }
            else if (fsmVar.Type == VariableType.Array)
            {
                FsmArray _target = fromFsm.Variables.GetFsmArray(fsmVar.variableName);
                _target.Reset();
            }
                        #endif
            return(true);
        }

        System.Type valueType = value.GetType();

        //Debug.Log("valueType  "+valueType);

        System.Type storageType = null;

        //	Debug.Log("fsmVar type "+fsmVar.Type);

        switch (fsmVar.Type)
        {
        case VariableType.Int:
            storageType = typeof(int);
            break;

        case VariableType.Float:
            storageType = typeof(float);
            break;

        case VariableType.Bool:
            storageType = typeof(bool);
            break;

        case VariableType.Color:
            storageType = typeof(Color);
            break;

        case VariableType.GameObject:
            storageType = typeof(GameObject);
            break;

        case VariableType.Quaternion:
            storageType = typeof(Quaternion);
            break;

        case VariableType.Rect:
            storageType = typeof(Rect);
            break;

        case VariableType.String:
            storageType = typeof(string);
            break;

        case VariableType.Texture:
            storageType = typeof(Texture2D);
            break;

        case VariableType.Vector2:
            storageType = typeof(Vector2);
            break;

        case VariableType.Vector3:
            storageType = typeof(Vector3);
            break;

        case VariableType.Object:
            storageType = typeof(Object);
            break;

        case VariableType.Material:
            storageType = typeof(Material);
            break;

                #if PLAYMAKER_1_8
        case VariableType.Enum:
            storageType = typeof(System.Enum);
            break;

        case VariableType.Array:
            storageType = typeof(System.Array);
            break;
                #endif
        }

        bool ok = true;
        if (!storageType.Equals(valueType))
        {
            ok = false;
            if (storageType.Equals(typeof(Object)))             // we are ok
            {
                ok = true;
            }
                        #if PLAYMAKER_1_8
            if (storageType.Equals(typeof(System.Enum)))             // we are ok
            {
                ok = true;
            }
                        #endif
            if (!ok)
            {
                                #if UNITY_WEBGL || UNITY_2017_1_OR_NEWER || UNITY_2018_1_OR_NEWER
                // proceduralMaterial not supported
                                #else
                if (valueType.Equals(typeof(ProceduralMaterial)))                 // we are ok
                {
                    ok = true;
                }
                                #endif
                if (valueType.Equals(typeof(double)))                 // we are ok
                {
                    ok = true;
                }
                if (valueType.Equals(typeof(System.Int64)))                 // we are ok
                {
                    ok = true;
                }
                if (valueType.Equals(typeof(System.Byte)))                 // we are ok
                {
                    ok = true;
                }
            }
        }


        if (!ok)
        {
            Debug.LogError("The fsmVar value <" + storageType + "> doesn't match the value <" + valueType + "> on state" + fromFsm.ActiveStateName + " on fsm:" + fromFsm.Name + " on GameObject:" + fromFsm.GameObjectName);
            return(false);
        }


        if (valueType == typeof(bool))
        {
            FsmBool _target = fromFsm.Variables.GetFsmBool(fsmVar.variableName);
            _target.Value = (bool)value;
        }
        else if (valueType == typeof(Color))
        {
            FsmColor _target = fromFsm.Variables.GetFsmColor(fsmVar.variableName);
            _target.Value = (Color)value;
        }
        else if (valueType == typeof(int))
        {
            FsmInt _target = fromFsm.Variables.GetFsmInt(fsmVar.variableName);
            _target.Value = System.Convert.ToInt32(value);
        }
        else if (valueType == typeof(byte))
        {
            FsmInt _target = fromFsm.Variables.GetFsmInt(fsmVar.variableName);
            _target.Value = System.Convert.ToInt32(value);
        }
        else if (valueType == typeof(System.Int64))
        {
            if (fsmVar.Type == VariableType.Int)
            {
                FsmInt _target = fromFsm.Variables.GetFsmInt(fsmVar.variableName);
                _target.Value = System.Convert.ToInt32(value);
            }
            else if (fsmVar.Type == VariableType.Float)
            {
                FsmFloat _target = fromFsm.Variables.GetFsmFloat(fsmVar.variableName);
                _target.Value = System.Convert.ToSingle(value);
            }
        }
        else if (valueType == typeof(float))
        {
            FsmFloat _target = fromFsm.Variables.GetFsmFloat(fsmVar.variableName);
            _target.Value = (float)value;
        }
        else if (valueType == typeof(double))
        {
            FsmFloat _target = fromFsm.Variables.GetFsmFloat(fsmVar.variableName);
            _target.Value = System.Convert.ToSingle(value);
        }
        else if (valueType == typeof(GameObject))
        {
            FsmGameObject _target = fromFsm.Variables.GetFsmGameObject(fsmVar.variableName);
            _target.Value = (GameObject)value;
        }
        else if (valueType == typeof(Material))
        {
            FsmMaterial _target = fromFsm.Variables.GetFsmMaterial(fsmVar.variableName);
            _target.Value = (Material)value;

                #if UNITY_WEBGL || UNITY_2017_1_OR_NEWER || UNITY_2018_1_OR_NEWER
            // proceduralMaterial not supported
                #else
        }
        else if (valueType == typeof(ProceduralMaterial))
        {
            FsmMaterial _target = fromFsm.Variables.GetFsmMaterial(fsmVar.variableName);
            _target.Value = (ProceduralMaterial)value;
                #endif
        }
        else if (valueType == typeof(Object) || storageType == typeof(Object))
        {
            FsmObject _target = fromFsm.Variables.GetFsmObject(fsmVar.variableName);
            _target.Value = (Object)value;
        }
        else if (valueType == typeof(Quaternion))
        {
            FsmQuaternion _target = fromFsm.Variables.GetFsmQuaternion(fsmVar.variableName);
            _target.Value = (Quaternion)value;
        }
        else if (valueType == typeof(Rect))
        {
            FsmRect _target = fromFsm.Variables.GetFsmRect(fsmVar.variableName);
            _target.Value = (Rect)value;
        }
        else if (valueType == typeof(string))
        {
            FsmString _target = fromFsm.Variables.GetFsmString(fsmVar.variableName);
            _target.Value = (string)value;
        }
        else if (valueType == typeof(Texture2D))
        {
            FsmTexture _target = fromFsm.Variables.GetFsmTexture(fsmVar.variableName);
            _target.Value = (Texture2D)value;
        }
        else if (valueType == typeof(Vector2))
        {
            FsmVector2 _target = fromFsm.Variables.GetFsmVector2(fsmVar.variableName);
            _target.Value = (Vector2)value;
        }
        else if (valueType == typeof(Vector3))
        {
            FsmVector3 _target = fromFsm.Variables.GetFsmVector3(fsmVar.variableName);
            _target.Value = (Vector3)value;

                #if PLAYMAKER_1_8
        }
        else if (value is System.Enum)          // valueType.BaseType == typeof(System.Enum)
        {
            FsmEnum _target = fromFsm.Variables.GetFsmEnum(fsmVar.variableName);
            _target.Value = (System.Enum)value;
                #endif
        }
        else
        {
            Debug.LogWarning("?!?!" + valueType);
            //  don't know, should I put in FsmObject?
        }


        return(true);
    }
コード例 #10
0
 public override void OnEnter()
 {
     array.Reset();
     Finish();
 }
コード例 #11
0
        public override void OnEnter()
        {
            /******************************
            *********** FsmVar ************
            ******************************/

            //you need to call .UpdateValue() before using an FsmVar
            variable.UpdateValue();
            if (variable.gameObjectValue != null)
            {
                //"Owner" returns the GameObject this FSM is attached to
                variable.gameObjectValue = Owner;
            }


            /******************************
            ******* Compound Arrays *******
            ******************************/

            //going through the elements of the compound array
            for (int i = 0; i < compareTos.Length; i++)
            {
                //skip if it's 'None'
                if (compareTos[i].IsNone)
                {
                    continue;
                }

                //send the event with the same index as the first array
                if (compareTos[i] == targetGameObject)
                {
                    Fsm.Event(compareEvents[i]);
                }
            }


            /******************************
            **** Pre-defined Variables ****
            ******************************/

            //examples of pre-defined variables that hold a specific, fsm-related value
            //that get derived from FsmStateAction
            Fsm      currentFSM       = Fsm;
            FsmState currentState     = State;
            string   currentStateName = Name;


            /******************************
            *********** FsmArray **********
            ******************************/

            //best to reset an FsmArrays values before using it to
            //make sure it doesn't keep any values when re-entering
            anyArrayResult.Reset();
            List <string> fieldValues = new List <string>();

            for (int i = 0; i < normalStringArray.Length; i++)
            {
                anyArrayResult.Set(i, (object)normalStringArray[i]);
            }

            anyArrayResult.SaveChanges();


            /******************************
            ********* Finish Event ********
            ******************************/

            //"Finished" returns wheter every action in the current state has been finished,
            //thus can be used to only send an event when every other action has finished
            if (Finished)
            {
                //if you want to send an event from your current action
                Event(onFinishEvent);
            }
            Fsm.SendEventToFsmOnGameObject(targetGameObject.Value, "FSM", onFinishEvent);
        }
コード例 #12
0
        public void splitText()
        {
            string _text;

            if (OrThisString.Value.Length == 0)
            {
                if (textAsset == null)
                {
                    return;
                }
                else
                {
                    _text = textAsset.text;
                }
            }
            else
            {
                _text = OrThisString.Value;
            }


            result.Reset();


            string[] rawlines;

            if (OrThisChar.Value.Length == 0)
            {
                char _split = '\n';

                switch (split)
                {
                case SplitSpecialChars.Tab:
                    _split = '\t';
                    break;

                case SplitSpecialChars.Space:
                    _split = ' ';
                    break;
                }


                rawlines = _text.Split(_split);
            }
            else
            {
                rawlines = _text.Split(OrThisChar.Value.ToCharArray());
            }



            int start = startIndex.Value;

            int count = rawlines.Length;

            if (parseRange.Value > 0)
            {
                count = Mathf.Min(count - start, parseRange.Value);
            }

            string[] lines = new string[count];

            int j = 0;

            for (int i = start; i < start + count; i++)
            {
                lines[j] = rawlines[i];
                j++;
            }

            result.Resize(count);


            if (parseAsType == ArrayParseStringAs.String)
            {
                result.Values = lines;
            }
            else if (parseAsType == ArrayParseStringAs.Int)
            {
                int i = 0;

                int _value_i = 0;

                foreach (String text in lines)
                {
                    int.TryParse(text, out _value_i);
                    result.Set(i, _value_i);
                    ++i;
                }

                result.SaveChanges();
            }
            else if (parseAsType == ArrayParseStringAs.Float)
            {
                int i = 0;

                float _result_float = 0f;
                foreach (String text in lines)
                {
                    float.TryParse(text, out _result_float);
                    result.Set(i, _result_float);
                    ++i;
                }

                result.SaveChanges();
            }
        }
コード例 #13
0
 public override void OnEnter()
 {
     TNManager.GetChannelList(_CallOnChannelList);
     storeValue.Reset();
 }
コード例 #14
0
 public override void Reset()
 {
     storeValue  = null;
     valuestring = null;
     storeValue.Reset();
 }