-
-
Save piyanggoon/a59cc6ae2d905c28021cf4b0fe067c96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using Sirenix.OdinInspector; | |
using UnityEngine; | |
public class CharacterHelper : SerializedMonoBehaviour | |
{ | |
public Dictionary<string, AnimatorStruct> AnimatorController; | |
void Update() | |
{ | |
if(AnimatorController.Count > 0) | |
{ | |
foreach(var Object in AnimatorController) | |
{ | |
switch(Object.Value.VaribleType) | |
{ | |
case VaribleType.Int: | |
if(ConditionInt(Object.Value.ConditionInt)) | |
{ | |
print("value (" + Object.Value.ConditionInt.value + ") : " + Object.Value.ConditionInt.ConditionType.ToString() + " : target (" + Object.Value.ConditionInt.target + ")"); | |
} | |
break; | |
case VaribleType.Float: | |
if(ConditionFloat(Object.Value.ConditionFloat)) | |
{ | |
print("value (" + Object.Value.ConditionInt.value + ") : " + Object.Value.ConditionInt.ConditionType.ToString() + " : target (" + Object.Value.ConditionInt.target + ")"); | |
} | |
break; | |
case VaribleType.Boolean: | |
if(ConditionBoolean(Object.Value.ConditionBoolean)) | |
{ | |
print("value (" + Object.Value.ConditionInt.value + ") : " + Object.Value.ConditionInt.ConditionType.ToString() + " : target (" + Object.Value.ConditionInt.target + ")"); | |
} | |
break; | |
case VaribleType.String: | |
if(ConditionString(Object.Value.ConditionString)) | |
{ | |
print("value (" + Object.Value.ConditionInt.value + ") : " + Object.Value.ConditionInt.ConditionType.ToString() + " : target (" + Object.Value.ConditionInt.target + ")"); | |
} | |
break; | |
} | |
} | |
} | |
} | |
private bool ConditionInt(ConditionStruct<int> Condition) | |
{ | |
if(Condition.ConditionType == ConditionType.Less) | |
{ | |
if(Condition.value < Condition.target) | |
{ | |
return true; | |
} | |
} | |
else if(Condition.ConditionType == ConditionType.Over) | |
{ | |
if(Condition.value > Condition.target) | |
{ | |
return true; | |
} | |
} | |
else if(Condition.ConditionType == ConditionType.Equal) | |
{ | |
if(Condition.value == Condition.target) | |
{ | |
return true; | |
} | |
} | |
else if(Condition.ConditionType == ConditionType.NotEqual) | |
{ | |
if(Condition.value != Condition.target) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
private bool ConditionFloat(ConditionStruct<float> Condition) | |
{ | |
if(Condition.ConditionType == ConditionType.Less) | |
{ | |
if(Condition.value < Condition.target) | |
{ | |
return true; | |
} | |
} | |
else if(Condition.ConditionType == ConditionType.Over) | |
{ | |
if(Condition.value > Condition.target) | |
{ | |
return true; | |
} | |
} | |
else if(Condition.ConditionType == ConditionType.Equal) | |
{ | |
if(Condition.value == Condition.target) | |
{ | |
return true; | |
} | |
} | |
else if(Condition.ConditionType == ConditionType.NotEqual) | |
{ | |
if(Condition.value != Condition.target) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
private bool ConditionBoolean(ConditionStruct<bool> Condition) | |
{ | |
if(Condition.ConditionType == ConditionType.Equal) | |
{ | |
if(Condition.value == Condition.target) | |
{ | |
return true; | |
} | |
} | |
else if(Condition.ConditionType == ConditionType.NotEqual) | |
{ | |
if(Condition.value != Condition.target) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
private bool ConditionString(ConditionStruct<string> Condition) | |
{ | |
if(Condition.ConditionType == ConditionType.Equal) | |
{ | |
if(Condition.value == Condition.target) | |
{ | |
return true; | |
} | |
} | |
else if(Condition.ConditionType == ConditionType.NotEqual) | |
{ | |
if(Condition.value != Condition.target) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
} | |
public struct AnimatorStruct | |
{ | |
public VaribleType VaribleType; | |
[ShowIf("VaribleType", VaribleType.Int)] | |
[HideLabel] | |
public ConditionStruct<int> ConditionInt; | |
[ShowIf("VaribleType", VaribleType.Float)] | |
[HideLabel] | |
public ConditionStruct<float> ConditionFloat; | |
[ShowIf("VaribleType", VaribleType.Boolean)] | |
[HideLabel] | |
public ConditionStruct<bool> ConditionBoolean; | |
[ShowIf("VaribleType", VaribleType.String)] | |
[HideLabel] | |
public ConditionStruct<string> ConditionString; | |
} | |
public enum VaribleType | |
{ | |
Int = 0, | |
Float = 1, | |
Boolean = 2, | |
String = 3 | |
} | |
public enum ConditionType | |
{ | |
Less = 0, | |
Over = 1, | |
Equal = 2, | |
NotEqual = 3 | |
} | |
public struct ConditionStruct<T> | |
{ | |
[LabelText("Condition")] | |
public ConditionType ConditionType; | |
public T target; | |
public T value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment